Site logo

[Resolved] Search bar assigns a title to the page

Home Forums Support [Resolved] Search bar assigns a title to the page

Home Forums Support Search bar assigns a title to the page

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #2549755
    Harsha Kiran Gudibandi

    When you search for a term and the results show, the search page gets assigned a title using the first result.

    How do I fix this?

    #2550146
    David
    Staff
    Customer Support

    Hi there,

    Can you share a link to your site ?

    #2552958
    Harsha Kiran Gudibandi

    https://www.adakta.co/?s=stats

    Here’s an example.

    #2553110
    David
    Staff
    Customer Support

    OK, so the site uses a Block Element titled in Appearance > Elements titled: Global Page Header
    And that was neveer meant for search results.
    To make it work for them:

    1. Add this PHP Snippet to your site:

    add_shortcode('multi_title', 'get_custom_title' );
    function get_custom_title() {
        if ( is_singular() ) {
            return get_the_title();
        } elseif ( is_search() ) {
            return 'Search results for: ' . get_search_query();
        } elseif ( is_archive() ) {
            return get_the_archive_title();
        } else {
            return get_bloginfo( 'name' );
        }
    }

    2. edited the Global Page Header Element.
    2.1 Select the Headline showing the title and uncheck the Dynamic Data option in the toolbar.
    2.2 replace the title text with this shortcode [multi_title]

    3. Publish the changes

    #2567020
    Harsha Kiran Gudibandi

    Hello again. Regarding step #1, where should I add the PHP snippet?

    #2567215
    David
    Staff
    Customer Support

    Oh sorry, this doc explains how to add PHP:

    https://docs.generatepress.com/article/adding-php/

    #2568742
    Harsha Kiran Gudibandi

    Hey David. Thanks for the help. It’s changed now. However, I have one more thing, https://www.adakta.co/?s=stats it’s not double. How do I remove one instance of it?

    #2568821
    Ying
    Staff
    Customer Support

    Try adding this PHP snippet as well to remove the original H1:

    add_action('wp',function() {
    	remove_action( 'generate_before_loop', 'generate_do_search_results_title' );
    });
    #2568974
    Harsha Kiran Gudibandi

    Perfect, thanks both

    #2568999
    Ying
    Staff
    Customer Support

    No Problem!

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.