Forums Forums Search & Filter Pro Page meta title on search page

Viewing 6 posts - 1 through 6 (of 6 total)
  • Anonymous
    #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
    #264115

    Let 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 it sf-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
    #264132

    Hi 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
    #264134

    The 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
    #264136

    Thanks 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 check

    You just have to use the Yoast “wpseo_title” filter.

    Thanks!

    Trevor
    #264138

    Thanks for sharing.

    I will close this thread for now.

Viewing 6 posts - 1 through 6 (of 6 total)