- This topic has 6 replies, 3 voices, and was last updated 5 months, 3 weeks ago by
David.
-
AuthorPosts
-
October 6, 2022 at 9:58 am #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.
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
October 6, 2022 at 7:08 pm #2365760Fernando 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
October 7, 2022 at 1:23 am #2365936Mihail
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?
Next, how do I tackle the 404 Page Problem and the Landing Page Appears Different
Thank you in advance!
Mihail.October 7, 2022 at 1:53 am #2365954Fernando 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
October 7, 2022 at 2:05 am #2365970Mihail
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.October 7, 2022 at 11:03 pm #2366775Mihail
Hello, do you have any updates about the problem?
Thank you,
Mihail.October 8, 2022 at 4:48 am #2366940David
StaffCustomer SupportHi 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.Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/ -
AuthorPosts
- You must be logged in to reply to this topic.