• Is it possible to customize the apperance of search result. My all posts have a embed code so that user can copy them and use that on their site. These code is also showing in the search result. Can I only show the title and the first paragraph of the article.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Hi there,

    tricky one… you can try this PHP Snippet to display an excerpt that contains only the first sentence:

    function filter_excerpt($excerpt) {
    	if ( is_search() ){
    		$excerpt = wp_strip_all_tags($excerpt); // Strip all HTML tags from the excerpt.
    		$excerpt = trim($excerpt); // Trim whitespace from the beginning and end of the excerpt.
    		$pos = strpos($excerpt, "."); // Find the position of the first full stop.
    		if ($pos !== false) {
    			$excerpt = substr($excerpt, 0, $pos + 1); // Get the substring up to and including the first full stop.
    		}
    		$excerpt = '<p>' . $excerpt . '</p>'; // Wrap the excerpt in <p> tags.
    	}
        return $excerpt;
    }
    add_filter('get_the_excerpt', 'filter_excerpt');
Viewing 1 replies (of 1 total)

The topic ‘customize search result’ is closed to new replies.