Hi everyone,
I’m customizing the header of my website in Vantage child-theme.
I see that “the_title();” call the function able to create the page title in the header.php, but the problem is when I try to save the name in a PHP variable just like:
$name = the_title();
… doesn’t work! Because that command is going to execute a piece of code I suppose.
So, how can I get the page name in a variable?
Thank you guys!
Hi please can I have a help?
Cheers guys
Sorry guys I know my questions are always strange, but your help is gold as always.
I just need to put the page title in other places and im working on the “header.php” file.
If I call this function:
the_title();
its gonna create a new header, instead is there a way to get the the “page title” and save it in a variable?
Thanks again guys
Hi Maxx,
You’re after get_the_title(). the_title() will automatically output the title while get_the_title will simply “get” the title (thus allowing you to do stuff with it).
You could also use the_title( null, null, false ) but there’s no reason to do that that over get_the_title().
Hi Alex,
that’s great! Thank you very much man, now it’s working and I see this is a WordPress function. In combination with some other PHP code ($full_path = “http://”.$_SERVER[‘HTTP_HOST’].$_SERVER[‘REQUEST_URI’];) I got custom header for every user profile.
In this case I can also extend the capabilities of the “header.php” a lot, I will publish the code here in the forum if this can be useful for somebody else :)
best!
Hi Max,
You need to escape those as what you’re currently doing allows for XSS. Please refer to esc_url for more information.
Hi Alex,
sorry I just read your reply right now.
Thanks a lot for your advice man, but is that necessary? Did you find something wrong in my additional code?
Hi Max,
Yes. This:
$full_path = “http://”.$_SERVER[‘HTTP_HOST’].$_SERVER[‘REQUEST_URI’];
Is vulnerable to XSS and it’s 100% necessary to escape those strings.
Sorry again for my late answer… im planning new medialist for my newsletter
now imworking again to khappa.com
wooooow, your’re right Alex and thanks for the advice but how can i get same thing in other way?