Forums Forums Search & Filter Pro Page Title using first post title

Tagged: 

Viewing 9 posts - 1 through 9 (of 9 total)
  • Anonymous
    #44536

    Greetings Ross & Trevor,

    Small issue, not critical, but would be nice to correct it if possible. On my search results pages, for the page title it is using the title of the first result – I found instructions for fixing it here:

    http://www.designsandcode.com/documentation/search-filter-pro/search-results/as-an-archive/

    (at the bottom under “Update Page Title”) However it doesn’t seem to be working.

    I have three forms that produce search results, so the only change I made was to change the form ID to an array, but it also didn’t work when I limited it to one form ID and tested that form – this is what I have in my functions file:

    add_filter('wp_title','search_form_title');
       function search_form_title($title){
       global $searchandfilter;
         if ( $searchandfilter->active_sfid() == array(724,725,727))
          {
          return 'Search Results';
          }
         else
         {
        return $title;
     }
    }

    I’m using WP 4.4.2 – is it possible that this no longer works with 4.4.2? Is there something I’m doing wrong?

    Trevor
    #44628

    Ross may well come back on this, but I do not think that this function (active_sfid) can take an array. Thus the code may have to be using ORs instead:

    add_filter('wp_title','search_form_title');
       function search_form_title($title){
       global $searchandfilter;
         if ( $searchandfilter->active_sfid() == 724) || ( $searchandfilter->active_sfid() == 725) || ( $searchandfilter->active_sfid() == 727)
          {
          return 'Search Results';
          }
         else
         {
        return $title;
     }
    }

    Maybe?

    Anonymous
    #44651

    Hi Trevor,

    Thanks for the suggestion – it makes perfect sense – I tried that (but to pass PHP syntax validation I had to surround the statements with another set of parenthesis so it was like this:

    if ( ($searchandfilter->active_sfid() == 724) || ( $searchandfilter->active_sfid() == 725) || ( $searchandfilter->active_sfid() == 727) )

    However it still didn’t work – the (browser) page title still shows the title of the first search result post….

    It’s not a huge deal, but I’m concerned about indexing, the confusion factor, and SEO – if Ross doesn’t have a suggestion when he gets back, I’ll probably just hard-code it to readh “Search Results” for all search results pages (which I *think* I can do using if(is_search) ?)

    Trevor
    #44666

    Hi Trisha

    My bad on the coding. It was late 🙁

    My guess is that Ross is going to be mega busy this week, but I will leave this in as requiring attention and bring it up with him.

    Anonymous
    #44719

    Thanks Trevor, this one is very low on my priority list since I can hard-code the title and I think for now I’ll just do that……the other two problems I have are much higher-priority, with the searching for metadata in related posts being the highest. 🙂

    Trevor
    #44720

    Hi Trisha

    I think if we can video conference this on Skype I will have a better chance of understanding what you are doing.

    Do you have skype and a webcam or mic?

    Trevor
    #44721

    I meant the meta stuff (from the other post).

    Ross Moderator
    #44983

    If you are not bothered about giving different names to different pages you can just do

    if ( $searchandfilter->active_sfid() )
    {
        return 'Search Results';
    }

    This should be applied to any search results page then.

    Thanks

    Anonymous
    #46906

    Update: Still not able to resolve this, but it’s low on my priority list – just thought you might be interested in where it stands.

    I’ve tried a dozen variations of the combination of code snippets from above plus a lot of other stuff I found at the WP Codex and Support forum, without any luck.

    I did find some vague information about wp_title being deprected, then undeprectated, currently in some sort of limbo but I’m not sure if it still works in my version of WP which is 4.4.2. I found some information that says theme developers should now be hooking into “wp_get_document_title” and/or “pre_get_document_title” and applying filters to “document_title_parts”…sigh…..so after a lot of reading and following examples I came up with this:

    
    add_filter('pre_get_document_title', 'fix_search_document_title',10);
    function fix_search_document_title() {
    	$title = apply_filters( 'document_title_parts', $title );
    	global $searchandfilter;
          if ( $searchandfilter->active_sfid() )
          {
          $title['title'] = sprintf( __( 'Search Results for “%s”' ), get_search_query() );
          }
          else
          {
        return $title;
     }
    }
    

    BUT it still doesn’t work….it still uses the post title from the first search result found as the page title.

    This should be way low on the priority list for you too, but at some point it’s a puzzle I’d like to solve.

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