Forums › Forums › Search & Filter Pro › Change page title for search results
- This topic has 13 replies, 4 voices, and was last updated 9 years, 6 months ago by Anonymous.
-
Ross Moderator(Private) September 25, 2014 at 7:46 pm #5068
Hey Jim apologies – are you using the plugin without Ajax?
Ross Moderator(Private) March 27, 2015 at 6:25 pm #14117Please see this thread for how to override it:
https://support.searchandfilter.com/forums/topic/search-results-page-title-tag/
I will be adding this to the plugin as an option in the near future.
Thanks
Anonymous(Private) March 27, 2015 at 6:47 pm #14123Thanks. I have to disable my SEO plugin (All-in-One SEO Pack) in order for this to work as well. Is this the only way around this?
After I put this code into my functions.php it displays in the title fine. However, I plan on adding multiple custom post types. Would I be able to target the different post types and display different titles for each?
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; } }
Anonymous(Private) March 27, 2015 at 6:52 pm #14124Follow-up. Looks like I can continue to use All-in-one SEO Pack if I just disable “Rewrite titles”. I will just manually edit my theme’s title tag to how I want but still retain the other features of this SEO plugin.
I’m still curious how I would be able to display a different title based on custom post type.
Ross Moderator(Private) March 27, 2015 at 8:08 pm #14126Hi Peter
Thanks for the updates – yeah the code above is just standard WordPress code for modifying your page title – https://codex.wordpress.org/Function_Reference/wp_title – and it does a check to see if it is Search & Filter form before updating.
If you want to extract any info you’d probably have to look at the global
$wp_query->query
– that would allow you to get at all the info that is being used – but it might be a bit of hard work formatting it the way you want.If you had multiple search forms and you wanted to check which one it was you would do:
if($sf_form_data->form_id()==797) { /* do stuff */ }
Thanks
Anonymous(Private) March 27, 2015 at 8:51 pm #14129Thanks, that worked!
Here’s the final code in my functions.php for anyone else that needs it. I am using two search forms in this example.
add_filter('wp_title','search_meta_title'); function search_meta_title($data){ global $sf_form_data; if($sf_form_data->form_id()==141) { return 'Restaurants'; } if($sf_form_data->form_id()==169) { return 'Hotels'; } else { return $data; } }
Anonymous(Private) May 19, 2015 at 3:16 pm #17871Hello!
I just joined the conversation because I used your (Peter’s) code in my site, but the page title is still “Blog” when the search form is submitted.
You can take a look to results here: twinmotion.abvent.com/?sfid=5867&lang=enand you can find the form here: twinmotion.abvent.com/distributors/?lang=en
the code I used in my functions.php is:
add_filter('wp_title','search_meta_title'); function search_meta_title($data){ global $sf_form_data; if($sf_form_data->form_id()==6184) { return 'Distributeurs'; } if($sf_form_data->form_id()==5867) { return 'Resellers'; } else { return $data; } }
If you search in the French language the results’ page title is the first h1 in the page.
Strange!what is going on?
-
AuthorPosts