different title on a single page
-
[ Moderator note: moved to How-to and Troubleshooting. ]
is it possible to change the title on a single page? For instance, if the title of your website is blee blah, can you change the title on just your blog page to blah blee?
http://www.cranberrypiedesigns.com
-
Do you mean the title in the tab of the browser or do you mean changing text in the header?
Conditional Tags should do the trick for you 🙂
Try this code , that might help you.
if( isset( $_GET[‘’page_id]) && $_GET[‘’page_id] == “594” ) { /*your title for blog page*/ } else { /*your title for rest of the page*/ }If this work for you, try this concept with page slug or page title, as page id is not a very reliable solution, in case you assign different page to blog.
ThanksI mean changing the text in the header, so that it is the same on all pages, but different on just one. Thank you everyone for your responses!
building upon @cedcommerce answer you can change the title by using the filter provided by WP. Place this code in the functions.php of your active theme
function my_custom_title() { if( isset( $_GET[‘’page_id]) && $_GET[‘’page_id] == “594” ) { /*your title for blog page*/ return "My Title For Blog"; } } add_filter( 'pre_get_document_title', 'my_custom_title', 10, 2 );This filter function works for WP installation after 4.4
If using older than 4.4 then use wp_title instead of pre_get_document_title
Thank you Woonninjas. I’ll give this a try. I assume it works for the sub-title as well. would I type in /*your sub title for blog page* ?
These are just comments @vickilh
/*your sub title for blog page*/This will work only for the Page title. Let me write with more clarity
the complete solution. Here just simply replace “Blog Page” with your page name.function my_custom_title() { global $post; $my_page_title = "Blog Page"; if( $my_page_title == $post->post_title ) { return "My Title For Blog"; } } add_filter( 'pre_get_document_title', 'my_custom_title', 10, 2 );okay. I tried to write my page name where it said “my title for blog” and I got a 500 error. had to have Bluehost rescue me. playing with the theme functions.php is a little scary. Can I paste this last batch of code at the end of the functions.php page? Do I do that in my child theme?
Hi Woonninjas- I copied and pasted the code in the gray area above, and replaced “Blog Page” with my page name. no luck.
Yes It’s better to place it in the child theme at the end of your functions.php file.
Which version of WP are you using. ?
wooninjas. I’m using wordpress 4.5.2
It should work then, are you sure you are doing it right.
Try to see If you are targeting the correct functions.php file by placing this on top of your file after <?php tag.die("I am inside functions.php")If the page is blank with this message then go ahead to verify that this filter works by.
function my_custom_title() { die("inside filter"); global $post; $my_page_title = "Blog Page"; if( $my_page_title == $post->post_title ) { return "My Title For Blog"; } } add_filter( 'pre_get_document_title', 'my_custom_title', 10, 2 );This is just for testing purpose, make sure you remove die() from both the places after testing.
Wooninjas: guess you’ll have to come over to my house and help me with this. I can’t make it work. I tried verifying the filter, and nothing at all happened. no blank page. no success with the other code you gave me. I think I give up. thanks for sticking it out with me for so long.
Well, I tested it on WP version 4.5.2 and It works fine. Not sure what you are missing. Maybe you should look a bit more on how to write custom functions in your theme’s functions.php file
Instead of
add_filter( 'pre_get_document_title', 'my_custom_title', 10, 2 );Try this.
add_filter( 'wp_title', 'my_custom_title', 10, 2 );
The topic ‘different title on a single page’ is closed to new replies.