在函数中。php:
function wpse82525_link_search_to_tag()
{
// check if search archive is being displayed
if( ! is_search() )
return;
// get search query var
$sqv = get_query_var( \'s\' );
// get tag base
$tagbase = get_option( \'permalink_structure\' )
? get_option( \'tag_base\' )
? trailingslashit( get_option( \'tag_base\' ) )
: \'tag/\'
: \'?tag=\';
// return link if matching tag is found
return ( get_term_by( \'slug\', $sqv, \'post_tag\' ) )
? \'<p>\' . sprintf(
__( \'Are you looking for our <a href="%1$s">%2$s</a> page?\', \'txtdomain\' ),
home_url( $tagbase . sanitize_title_with_dashes( $sqv ) ),
$sqv
) . \'</p>\'
: \'\';
}
正在搜索中。php:
<?php echo wpse82525_link_search_to_tag(); ?>