Trim the search result around the search word

A random thought: put the search string into an array ( with explode). Find the array position of the highlighted string. Count back xx for the start, and forward xx for the end. Extract those array values, then implode them back into a string. That would work for one searchresult word in the string. You’d … Read more

Template Page Content Made Searchable

By default WordPress cannot search in template content. You should import your content into the data base. The plugin HTML Import 2 will help here. Another option is a separate search engine with a parser that can read the complete HTML output. The plugin Search Unleashed for example supports Apache Lucene. That’s probably too much … Read more

How to show a random selection of posts from the search

This is easy to do using the pre_get_posts action hook to set the orderby to rand in the query, something like this: function random_search_result( $q ) { if ( is_search() && is_main_query() ) $q->set( ‘orderby’, ‘rand’); } add_action( ‘pre_get_posts’, ‘random_search_result’ );