[Resolved] Customize the search result and its title.

Home Forums Support [Resolved] Customize the search result and its title.

Home Forums Support Customize the search result and its title.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
  • #2024440

    Hi, I have three questions about how to display the search result:

    1. In the presentation of my project category I have used one of the Content Templates and I like it very much (link 1), however in my search result the same template does not apply. I would like to create a new template for that result, so that I get a simple listing in one column and not in three, as in Projects. How can I present my search results in a single column?

    2. In the title of the search result, I wanted to change it with template block, however I get my first element, and what I really want to change is the title, i.e.: “Search result for : ” see my link 2

    3. In the search result I would like to customize it so that it only shows me the pages, and articles and not the directories, or categories that I would like to have private, as you can see in the link of my example. how could I solve it please ?

    Thank you !

    Customer Support

    Hi Beatriz,

    1.This article should help for the column settings:

    2.For the search result title, you can try this PHP snippet:

    function custom_search_result_title( $items) { 
       if ( is_search() ) { 
          $items = str_replace( "Search Results for", "Search custom Results for", $items ); 
       return $items; 
    add_filter( 'generate_search_title_output', 'custom_search_result_title', 9999, 2 ); 

    Replace the Search custom Results for with your custom title.

    3. GP has no control of the WP search output, here’s a snippet can be used on navigation search to customize the output of the navigation search:

    If you only want to show the posts and pages in search result page, try this PHP snippet:

    add_filter( 'generate_navigation_search_output', function() {
            '<form method="get" class="search-form navigation-search" action="%1$s">
                <input type="search" class="search-field" value="%2$s" name="s" title="%3$s" />
                <input type="hidden" name="post_type" value="post" />
                <input type="hidden" name="post_type" value="page" />
            esc_url( home_url( '/' ) ), 
            esc_attr( get_search_query() ),   
            esc_attr_x( 'Search', 'label', 'generatepress' ) 
    } );

    Let me know if this helps 🙂

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


    Thank you for your reply Ying.
    1. super! it works! now I have to sort out the formatting a bit.

    2. I tried the code and it works but it doesn’t solve what I want to do. I don’t really want to change the title string. What I want is to present the title in a hero block. I tried it with the template content but what it shows, is the first article of my search result (as shown in my private link).

    3. I tried the code but I still do not see much change, what I see in my search result, is that the contents are presented very different from each other without me finding a possible relationship. Some results only show the title, others the title plus the image and others the title, the image, the text and the read more button, independently if they are articles or pages. (see the link). I don’t understand why.

    Customer Support

    1. Glad to hear that 🙂

    2. Search result or blog page doesn’t have its own page title, so it will automatically use the first post’s title as its title. I don’t see a way to add the dynamic title into a block element at this moment Unfortuanly. You might need to use CSS to style the default search results for xsection.

    3. The reason that some of them show the excerpt some not is that some of the text nested in a container block which stops WP generate expert automatically (it’s a known Gutenberg bug). If you assign a block element – content template to the search result page, the excerpt nested in GB container might show.

    For some posts that don’t have thumbnails, it’s likely they don’t have a featured image assigned in the page editor.


    Thank you Yin,
    2- The page that lists the search results, has a title, with a phrase beginning with “RÉSULTATS DE RECHERCHE POUR :” and ending with the search term. This is the title that I want to put in a header, but when I try to do it with a block, the title is taken from the first post that is found. So two H1 are generated, the title of the post and the title of the page. But it is not serious, I will create a header only with a static image.

    3 – I understand that some results do not show the image because there is no image. However, I have used the content template and there is still the same problem with the excerpt. I can see that some posts that belong to x category, are displayed and others are not. Or some pages that are child pages do not show the excerpt either.

    Customer Support

    In the content template, do you have a dynamic content block in it to show the excerpt?

    Let me know 🙂


    yes, it does, but it is present in some results and not in others.

    Customer Support

    I just tested, seems even using dynamic content block in content template can’t get around the WP bug.

    In that case, I would recommend using custom excerpt, or move the text out of the container block in the post.

    Let me know.


    Hi Ying! sorry for the delay, indeed, when the text is inside a block, the excerpt does not appear.
    I can solve it with the articles but not with the content of my static pages.
    A simple option, for the moment, is to present only the title and the image, as a result of the search.
    Thank you !

    Customer Support

    You are welcome 🙂

    I hope WP can get this bug fixed soon, it’s really annoying sometimes.

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