How can I just show the post content in a search result? Currently, the search results displays the post title, author and date above the page content.
Here is how it looks now: http://sikkervaccination.dk/?s=thailand
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.
Sign up to join this communityHow can I just show the post content in a search result? Currently, the search results displays the post title, author and date above the page content.
Here is how it looks now: http://sikkervaccination.dk/?s=thailand
Some themes like Twenty Fourteen include a template tag included in the content.php file for entry meta which includes the author and date:
Example:
twentyfourteen_posted_on();
The content.php file also includes the_title()
tag so you need to remove that if you don't want the entry titles displaying on your search result pages.
The search.php file includes this tag which includes the content.php
get_template_part( 'content', get_post_format() );
To display content only on the search results pages, you would need to create your own custom search.php file.
To do this using the Twenty Fourteen theme for example, copy over the search.php file to a child theme and modify the code there.
You could then copy over the content.php file from your parent theme to your child theme, rename it to something like customsearch.php and change the template template in your child themes search.php file to:
get_template_part( 'customsearch' );
Then you simply modify your customsearch.php file in your child theme and your code is saved from any parent theme updates.
You can usually modify the display of your search results by editing a loop in search.php
file in your theme folder. It depends on your theme, though. Some themes may have this code located in another file, like loop.php
, loop-search.php
or loop-posts.php
to give you some examples, but you should start by looking at the search.php
file.
In your post loop in search.php, add this code
the_content(); // use this line or use below one
echo get_the_content($post->ID);