[Support request] Problem With “Search Results For”, 404 Page & Page Shows Differently

Home Forums Support [Support request] Problem With “Search Results For”, 404 Page & Page Shows Differently

Home Forums Support Problem With “Search Results For”, 404 Page & Page Shows Differently

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #2365486
    Mihail

    Hello, I have three problems that I can’t figure out to do myself. I tried and searched throughout the forum, but can’t find a solution, unfortunately.

    Edit “Search Results For:
    I am having trouble editing the H1 Page Title when I type something in the Search Bar on my website. For example if I write “LAPTOP” it goes to another page with my archives with H1 Page Title: “SEARCH RESULTS FOR: LAPTOP”.

    How do I change the layout of this? For example for it to appear in the center and not left aligned. How do I change the size of the text etc?

    Sorry if I may sound confusing, I don’t know how to explain this better. I include screenshots of what I am trying to explain in Imgur.
    https://imgur.com/a/sk9Lptk

    404 Page Problem
    I created a custom 404 Page. It gets linked to that page when somebody types something that doesn’t exist.

    However, I added 100px Top Padding on the entire container, but it doesn’t apply in live view. Also, styling doesn’t appear on “MAYBE TRY TO SEARCH” text. I tried clearing website cache and also browser cache, but the probelm doesn’t go away. What is the cause of this?

    Landing Page Appears Different
    Also, some areas of my landing page are totally misaligned in the live version. When I edit, everything shows fine. I am having a constant issue with this.

    I would appreciate any help you could provide.

    Kind regards

    #2365760
    Fernando
    Customer Support

    Hi Mihail,

    Let’s tackle one issue at a time starting with the Search Page title.

    One solution is to create a Block Element – Page Hero.

    Then, add a Headline Block and set it to display to your liking.

    Add class hero-title to the Headline in its Advanced section, then add this snippet:

    add_filter( 'generate_dynamic_element_text', function( $text, $block ) {
        if ( is_search() && ! empty( $block['attrs']['className'] ) && 'hero-title' === $block['attrs']['className'] ) {
            $text = 'Search Results For: ' . get_search_query();
        }
    
        return $text;
    }, 10, 2 );

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

    #2365936
    Mihail

    Hello Fernando,

    I did everything you said, and it is working properly now. Thank you very much.

    However, SEARCH RESULTS FOR: EXERCISES is not replaced with SEARCH RESULTS ON THIS WEBSITE and shows below it. I attached a screenshot of it. How do I get rid of it, so only SEARCH RESULTS ON THIS WEBSITE exists?

    Also, how can I use dynamic content for SEARCH RESULTS ON THIS WEBSITE: “KEYWORD WRITTEN IN THE SEARCH BAR” to appear, just like SEARCH RESULTS FOR: EXERCISES appears?

    https://imgur.com/qIVi8Ie

    Next, how do I tackle the 404 Page Problem and the Landing Page Appears Different

    Thank you in advance!
    Mihail.

    #2365954
    Fernando
    Customer Support

    I see. You added hero-title as an anchor/ID. You’ll need to add it as a CSS class for the code to work.

    Replace the snippet to this:

    add_filter( 'generate_dynamic_element_text', function( $text, $block ) {
        if ( is_search() && ! empty( $block['attrs']['className'] ) && 'hero-title' === $block['attrs']['className'] ) {
            $text = 'SEARCH RESULTS ON THIS WEBSITE: ' . get_search_query();
        }
    
        return $text;
    }, 10, 2 );

    Then, disable the title in the settings of the Block Element: https://docs.generatepress.com/article/block-element-page-hero/#disable-title

    #2365970
    Mihail

    Thank you for the quick reply Fernando. I appreciate it.

    I applied the suggestions, but I am afraid nothing changed. I also cleared the browser and website cache. Can you please check on your end to see if the changes took place?

    Thank you in advance,
    Mihail.

    #2366775
    Mihail

    Hello, do you have any updates about the problem?

    Thank you,
    Mihail.

    #2366940
    David
    Staff
    Customer Support

    Hi there,

    remove the PHP Snippet and the Block Element.
    And try adding this snippet instead:

    function custom_search_result_title( $items) { 
       if ( is_search() ) { 
          $items = str_replace( "Search Results for", "Your replacement search text", $items ); 
       } 
       return $items; 
    } 
    
    add_filter( 'generate_search_title_output', 'custom_search_result_title', 9999, 2 ); 

    Swap the Your replacement search text string in the code above fro the message you require.

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