Support Forums

The forums are closed and will be removed when we launch our new site.

Looking for support? You can access the support system via your account.

Forums Forums Search & Filter Pro Search Results Page Title Tag

Tagged: 

Viewing 10 posts - 1 through 10 (of 13 total)
  • Celeste
    #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,
    Celeste

    Ross Moderator
    #10810

    Hey 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

    Celeste
    #10973

    Hi Ross, thanks for the reply. I tried this just as you have it, and it didn’t have an effect on the page title. Do I need to add anything to the search results template, or just add this to functions.php?

    Thanks.

    Ross Moderator
    #11374

    Hi Celeste

    Apologies I thought I replied to this – did you try the above code with the SEO plugin disabled?

    Thanks

    Celeste
    #11472

    Strange, 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,
    Celeste

    Ross Moderator
    #11475

    He Celeste

    You’ve obviously removed something, or the plugin is disabled

    It might be the global $sf_form_data as the is_valid_form requires this.

    Thanks

    Celeste
    #11488

    Hi Ross, the plugin is active and nothing has been removed.

    I replaced global $post; with global $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!
    Celeste

    Celeste
    #11491

    Hey 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
    #11515

    Hey 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

    Celeste
    #11527

    Thanks 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

Viewing 10 posts - 1 through 10 (of 13 total)

The forum ‘Search & Filter Pro’ is closed to new topics and replies.