Passing wordpress title into a php variable

this…does not work :slight_smile:

$title = wp_title( );

likely a syntax thing that I cant get my tired head and eyes around. As soon as wp_title( ); is mentioned, the title is automatically output on the blog which is not what i want.

I need to get the title of the current page into a variable so i can then do stuff on it:)

ah now i understand thanks guido, so it should be something like

$title = wp_title(,0,);

I will try it when i get back, have to run out to the day job (sigh)

I quote from the page I linked to:

$echo
(boolean) (optional) Echo the title (True) or return the title for use as a PHP string (False).

    Default: True 

    * 1 (True) - default
    * 0 (False)

Yes, it’s the same function :slight_smile:
If the OP reads the codex, he’ll find the answer :wink:

Try using the output buffering functions:


ob_start();
wp_title();
$title = ob_get_clean();

echo $title;

Although, I don’t know WordPress but I’d imagine there’s some function that will return the title…

Err, thanks guys but I did but i dont see the solution. I need to put the title into a php variable. I dont see it there…?

Ah, so it is.

I thought it was unlikely that a well-known system such as WordPress lacked this :slight_smile: