- This topic has 10 replies, 4 voices, and was last updated 4 years, 11 months ago by Leo.
-
AuthorPosts
-
January 20, 2019 at 5:56 am #786913Marius
With the help from the plugin 404page, I want to make a separate 404 page.
But how can I put the search field in there, like in the standard 404 page from GP?
January 20, 2019 at 9:47 am #787184TomLead DeveloperLead DeveloperHi there,
You could create a shortcode which will output the form for you:
add_shortcode( 'search_form', function() { ob_start(); get_search_form(); return ob_get_clean(); } );
Then you could use this on your page:
[search_form]
January 20, 2019 at 9:58 am #787199MariusOkay, but where to put this code? I have searches for it and find this: https://docs.generatepress.com/article/creating-a-shortcode/
But it doesn´t say, where to put the code.
January 20, 2019 at 9:58 am #787200TomLead DeveloperLead DeveloperSorry about that 🙂
You can add it using one of these methods: https://docs.generatepress.com/article/adding-php/
January 20, 2019 at 10:06 am #787215MariusHmm, I have done so, but when openig this site, I get this error:
Warning: Cannot modify header information – headers already sent by (output started at /www/htdocs/xxx/domain.net/wp-includes/general-template.php:241) in /www/htdocs/xxx/domain.net/wp-includes/pluggable.php on line 1223
January 20, 2019 at 10:16 am #787223TomLead DeveloperLead DeveloperSorry about that – I just adjusted the code above: https://generatepress.com/forums/topic/search-field-in-404-page/#post-787184
Can you give it another shot?
January 20, 2019 at 10:25 am #787236Mariusokay, now it workes. Thank you Tom.
January 20, 2019 at 5:43 pm #787439TomLead DeveloperLead DeveloperYou’re welcome 🙂
February 9, 2020 at 1:26 pm #1159963DanaHello GP support team,
If you would like me to start a new topic I can. I just figured this is relevant to the current topic.
I have used the
search_form
shortcode above to add to a couple of Elements; one for my 404 page and one for my search page.I also used the filter suggestion and code to exclude pages from my search and only focus on posts being returned in the search results and it works from the nav search.
The filter suggestion is not working for my
search_form
shortcode as searching from either my 404 or search pages where thesearch_form
shortcode is declared returns pages in the results.Is there a way to have the same filter applied to the
search_form
shortcode? Or is the filter only specific to the navigation bar search? I took a peek at the other filters and I didn’t see another filter that I could use.Thanks in advance.
February 9, 2020 at 1:48 pm #1159973DanaHi GP Team,
You can disregard my question. I figured it out.
Thanks.
I thought I would post the code I used in case anyone else wants to do the same.
add_shortcode( 'search_form', function() { ob_start(); printf( '<form method="get" class="search-form" action="%1$s"> <input type="search" placeholder="Search mysite.com" class="search-field" value="%2$s" name="s" title="%3$s" /> <input type="submit" value="Search"> <input type="hidden" name="post_type" value="post" /> </form>', esc_url( home_url( '/' ) ), esc_attr( get_search_query() ), esc_attr_x( 'Search', 'label', 'generatepress' ) ); return ob_get_clean(); } );
February 9, 2020 at 3:09 pm #1160027LeoStaffCustomer SupportGlad you’ve figured out 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.