WordPress Single Conditional for Search Page

You could hook into the the_permalink filter and check for is_search() to conditionally modify the URLs of your search results to include some additional parameters that your single.php then checks for. Something like this (may require tinkering):

add_filter( 'the_permalink', 'wpse155331_the_permalink' );
function wpse155331_the_permalink( $url ) {
  if ( is_search() ) {
    $url = add_query_arg( array( 'from_search' => 'true' ), $url );
  }
  return $url;
}

Leave a Comment