Archived topic
Search form customization
3 replies · Started by Tanya on March 26, 2018
Hi Tom,
I am wrestling with the Search page and wondering if you could give me an advice how to best handle its customization within GP theme.
I like how GP search looks and would want something similar. Through my research I came across a couple of approaches to customize search:
1. Working with themes's filters and actions
2. Creating a child theme and overriding search.php and searchform.php
3. Using search plugin
Challenges:
1. So far I played with option #1. For example, I used "generate_before_main_content" action to add search box to the search page only. However, it added the search to the rest of the site, which I don't want. generate_before_entry_title adds multiple searches because its a loop.
2. I'd like to center content on the page (add 3 columns and put content in the middle). Not sure which action would allow me to do that.
3. Excerpts are not showing, neither does content (only page links show). I added "add_post_type_support( 'page', 'excerpt' );" to my code and now I can see excerpts box on my pages. I don't really want to summarize every page manually. Is there a way page excerpt automatically gets generated just based of the 1-st couple of sentences on a page?
4. Featured image was showing. To remove it I used the code below. It works, but I'm not sure if it is the best approach. As with challenge #1, this filter looks global and my featured image may not be displayed, when I need it in other places. How do I specify that I want to filter it out only on search page?
add_filter( 'generate_featured_image_output', 'my_featured_image_output' );
function my_featured_image_output(){
}
Thanks
Hi there,
1. You would need a conditional tag is_search(). Example here: https://docs.generatepress.com/article/generate_show_excerpt/#examples
2. You would just have to use a hook to enter the columns plus some CSS which we can help.
3. The first link I provided actually does this as well: https://docs.generatepress.com/article/generate_show_excerpt/#examples
4. Same as #1: https://codex.wordpress.org/Conditional_Tags#A_Search_Result_Page
Let me know if you need more info :)
Thanks Leo,
Questions 1,3,4 are resolved.
Could you please elaborate on #2.
I'd like all content, including search space to be centered on the page, similar how generate press search looks.
I used "Inside Content Container" hook to add search bar.
<?php if(is_search()) : ?>
<div class="container">
<?php get_search_form(); ?>
</div>
<?php endif; ?>
I suspect I need to use "Before Content" hook to center Search contents? Not sure how to reference and place search result output into a
Thanks
I would try the after header hook without the <div class="container">, then simply center with this CSS:
form.search-form {
text-align: center;
}