Forums Forums Search & Filter Pro Change page title for search results

Viewing 10 posts - 1 through 10 (of 14 total)
  • Anonymous
    #4729

    I have used a custom search page for the search results. How do I change the page title. It comes up “Blog”

    Thanks

    Anonymous
    #5038

    Anyone ?

    Ross Moderator
    #5068

    Hey Jim apologies – are you using the plugin without Ajax?

    Anonymous
    #14070

    I have a somewhat similar problem. The page title for mine is displaying the name of the first post title (custom post type) on the page. I am using AJAX and the archive page.

    Ross Moderator
    #14117

    Please 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
    #14123

    Thanks. 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
    #14124

    Follow-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
    #14126

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

    Thanks, 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
    #17871

    Hello!
    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=en

    and 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?

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