Forums › Forums › Search & Filter Pro › Page meta title on search page
Tagged: meta title, search page
- This topic has 5 replies, 2 voices, and was last updated 4 years ago by Trevor.
-
Anonymous(Private) October 26, 2020 at 10:54 am #264093
Hi there,
currently, the search page (using display results as an archive) shows as meta title “Blog – Sitename”.
It is possible to change this meta to show something else than “Blog”?
I’m using Yoast for all the other pages and it is working fine, just with Search and Filter seems that I can’t change the page meta title and I’m stuck on “Blog”.Sidenote:
The search functionality on this support forum is almost unuseable.
I mean, if I do a search, would be nice and useful to get just the post title and link instead of a list of the same thread with the different replies, with a preview of the content too that requires long scrolling to check the next result.
Finding an eventual usueful thread is almost impossible in this way.
Sorry for this note.Thank you.
Trevor(Private) October 26, 2020 at 12:28 pm #264115Let us assume that you are using the
search.php
template file. You would ned to be using a child theme, and copy and rename that parent theme file to the child theme folder, let us suppose that you renamed itsf-search.php
You would then edit the code in that file, where it is outputting the title, to be a title that you want. How this is coded in the theme template file varies, so where and what part you would need to edit will vary.
Anonymous(Private) October 26, 2020 at 2:27 pm #264132Hi Trevor, thanks for the reply.
No, I’ve developed my personal theme, no childs involved.
The page meta title tag is generated via Yoast plugin through the “wp-head()” function placed into header.php WP file.
Currently I’m using display as archive using a custom php template file, let’s call it like yours for easy understanding, sf.search.php, that is calling “get_header()” that calls “wp_head()” in header.php that will call Yoast SEO plugin in order to generate the <title> meta tag.So, I would like to know how that archive template is going to generate the meta title as “blog”.
Doing a google search I’ve found a thread on this forum about a similar problem (funny that if I try to search here I can’t find it! 😀 ):
https://support.searchandfilter.com/forums/topic/search-results-page-title-tag/
By the way that’s a 2015 thread, with some code hints that I’m not really sure they will work due to the plugin changes in the last 5 years.
Thank you.
Trevor(Private) October 26, 2020 at 2:37 pm #264134The page title is handled by WordPress, not our plugin, hence in that thread you read Ross was not entirely sure what would work and what would not.
WordPress relies on the theme template (or any plugin that intercepts that, or is called by that), but again that is in no way influenced or controlled by our plugin.
There are WordPress hooks to control the title, but it is likely that Yoast is intercepting these anyway.
wp_title
is what you would search for. There is standard functions.php code that should work if the theme and any other plugin do not interfere:add_filter('wp_title','search_form_title'); function search_form_title($title){ global $searchandfilter; if ( $searchandfilter->active_sfid() ) { return 'Search Page Title You Want'; } else { return $title; } }
Anonymous(Private) October 26, 2020 at 2:48 pm #264136Thanks for the pointing Trevor.
Solved.Following the code to be used in case of Yoast active on your website:
add_filter('wpseo_title', 'filter_search_wpseo_title'); function filter_search_wpseo_title( $title ) { global $searchandfilter; if( ! is_admin() && isset( $searchandfilter ) ) { if ( $searchandfilter->active_sfid() ) { return 'Search Page Title You Want'; } } return $title; }
** edited 27/10/2020 to include
is_admin
&isset
checkYou just have to use the Yoast “wpseo_title” filter.
Thanks!
-
AuthorPosts