Forums › Forums › Search & Filter Pro › Search Results Page Title Tag
Tagged: title tag
- This topic has 12 replies, 2 voices, and was last updated 9 years, 10 months ago by Ross.
-
Anonymous(Private) January 22, 2015 at 3:32 pm #10787
Hello.
The title on my search results page is displaying as Blog (the title tag, not the h1 page title). I am using WordPress SEO by Yoast which rewrites Titles & Meta. I assume it doesn’t recognize the slug (product-search) and is assigning the generic Blog title to this archive.
Do you know any way to force a different title tag on the search results page? Or is this a problem for WordPress SEO?
Thanks for your help,
CelesteRoss Moderator(Private) January 22, 2015 at 8:31 pm #10810Hey Celeste
So we could do something similar to before – this link mentions how to update the page title:
http://wordpress.stackexchange.com/questions/33101/how-do-i-set-the-page-title-dynamically
add_filter('the_title','some_callback'); function some_callback($data){ global $post; // where $data would be string(#) "current title" // Example: // (you would want to change $post->ID to however you are getting the book order #, // but you can see how it works this way with global $post;) return 'My Search Results'; }
And this (untested) would be a way to to update only for Search & Filter results:
add_filter('the_title','some_callback'); function some_callback($data){ global $post; // where $data would be string(#) "current title" // Example: // (you would want to change $post->ID to however you are getting the book order #, // but you can see how it works this way with global $post;) if ( $sf_form_data->is_valid_form() ) { return 'My Search Results'; } else { return $data; } }
Again, it should work on a normal setup, but YOAST might overwrite that, if thats the case I would look in to setting it at a lower priority.
Thanks
Ross Moderator(Private) February 3, 2015 at 8:22 pm #11374Hi Celeste
Apologies I thought I replied to this – did you try the above code with the SEO plugin disabled?
Thanks
Anonymous(Private) February 4, 2015 at 2:18 pm #11472Strange, I added the function back to functions.php and now I get this error message: “Fatal error: Call to a member function is_valid_form() on null in …/functions.php on line 324.”
This didn’t happen the first time I copied it into my functions file. The site still worked normally with no change to the title. Both times I copied it exactly as you have it.
By the way, I tried the original function from Stack Exchange just to see if it affected the page title, and it changed the h1 title on all pages, not the meta tag title.
Thanks,
CelesteRoss Moderator(Private) February 4, 2015 at 3:00 pm #11475He Celeste
You’ve obviously removed something, or the plugin is disabled
It might be the
global $sf_form_data
as theis_valid_form
requires this.Thanks
Anonymous(Private) February 4, 2015 at 4:50 pm #11488Hi Ross, the plugin is active and nothing has been removed.
I replaced
global $post;
withglobal $sf_form_data
in the function you posted above, and no longer receive the error message. However, the function is now replacing all menu items (page titles) on the search results page with “Search Results”. The meta title remains blog. I deactivated WordPress SEO and it didn’t change anything. You can see what’s happening here.I am already using some code you previously gave me to change the h1 page title. The new function is not affecting that and it still displays properly. It’s the only title on that page not affected.
I believe the_title changes the page or post title, not the seo title. I couldn’t find a function in the codex that targets the seo title only. I believe this will work if I could target the correct attribute. Do you have any other ideas how to change it without affecting regular page titles?
Sorry this is so convoluted. I really appreciate all your help!
CelesteAnonymous(Private) February 4, 2015 at 5:14 pm #11491Hey Ross, apologies for double posting, but I found the correct function to target the meta title, wp_title. So now my code looks like this:
add_filter('wp_title','search_meta_title');
function search_meta_title($data){
global $sf_form_data;
if ( $sf_form_data->is_valid_form() )
{
return 'Product Search Results';
}
else
{
return $data;
}
}
The function works perfectly when WordPress SEO is deactivated, but the title returns to “Blog” when I reactivate it. Do you know any way to override the WordPress SEO titles?
Ross Moderator(Private) February 5, 2015 at 11:25 am #11515Hey Celeste
Thanks for getting the right code – providing code without testing rarely ends well 😉
RE the SEO titles – I’m afraid not! I think this query would have come up a few times with their plugin so I would suggest reading their documentation or reaching out to the developer?
Its a huge plugin and been around for a long time so I’m guessing there are already some filters/hooks for this purpose.
Thanks
Anonymous(Private) February 5, 2015 at 1:39 pm #11527Thanks Ross. I’ve searched the WordPress SEO docs and haven’t found a way to overwrite a single archive title. I’ve posted a question on their forum. We’ll see if they’re as helpful as you (not holding my breath)!
Thanks again for everything,
Celeste -
AuthorPosts