I am new to programming and learning with WordPress.
the_title(); //outputs the title of the page
I want to capture the title of the page into a string variable so I can manipulate it with strtolower and str_replace functions.
The only way I have gotten it to work is with output buffering.
ob_start(); the_title(); $result = ob_get_clean(); echo str_replace(' ','-',strtolower($result)); /*there has got to be an easier way.... i dont fully understand why */ str_replace(' ','-',strtolower(the_title()));
What am I doing wrong?
If what you really are looking for is the
wp_titlefunction, the 2nd argument it takes is a boolean on whether or not it should display it or return it. Pass it false so it will return it to the var, then you can do this:Otherwise, your only option is to find the function you’re looking for and modify the source code.