Search result page title at top of the browser

  • Author
    Posts
  • #72966

    Here’s the issue we’re having on my client’s site..

    She wanted search results to open in a new page/tab, so we set it up that way.
    We are using the AJAX Search Pro search plugin instead of the default.
    I already reached out to the plugin developer, and he says the issue is theme related and not the AJAX Search Pro plugin.

    The problem..
    When a search is submitted, the search itself works fine.
    However, by looking at this screenshot you’ll see the issue.

    The page title of the search results page displays “Home” – and she wants it to say “Search Results” instead.
    The issue

    I am using a child theme, so I tried entering the following code to the child theme’s functions.php (code that I found online -I am not a PHP programmer)..

    /**
     * Modify the document title for the search page
     */
    add_filter( 'document_title_parts', function( $title )
    {
        if ( is_search() ) 
            $title['title'] = sprintf( 
                esc_html__( 'Search Results', 'my-theme-domain' ), 
                get_search_query() 
            );
    
        return $title;
    } );
    /**
     * Modify the page part of the document title for the search page
     */
    add_filter( 'document_title_parts', function( $title ) use( &$page, &$paged )
    {
        if ( is_search() && ( $paged >= 2 || $page >= 2 ) && ! is_404() ) 
            $title['page'] = sprintf( 
                esc_html__( 'Search Results', 'my-theme-domain' ), 
                max( $paged, $page ) 
            );
    
        return $title;
    } );

    But this didn’t work.
    So I removed it from the child theme when I found it was not working.

    Have you any suggestions?

    Thank you.

    Website: cinnsroadtrip.blog

    #73355
    Zed
    Cryout Creations Team

    Page (and section titles in general) are handled by WordPress. If you’re looking to customize theme, you should try a SEO plugin (Yoast has such a feature).


    If you like our creations, help us share by rating them on WordPress.org.
    Please read the available documentation and search the forums before posting.
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Search result page title at top of the browser’ is closed to new replies.