WordPress函数:输出搜索关键词标签之函数the_search_query

追格官方小助手/ 2022年04月09日/ WordPress/ 浏览 1422

WordPress主题标签the_search_query用于输出搜索关键词,下面是WordPress函数the_search_query的详细用法。


函数描述:

显示搜索查询的内容。应通过esc_attr()函数确保它是安全的再显示在HTML标签上。


代码示例:

function the_search_query() {
    /**
     * Filters the contents of the search query variable for display.
     *
     * @since 2.3.0
     *
     * @param mixed $search Contents of the search query variable.
     */
    echo esc_attr( apply_filters( 'the_search_query', get_search_query( false ) ) );
}


search.php中放置如下代码,该函数不带参数,下面的两种方式输出的结果一致


<?php the_search_query(); ?>

<?php echo esc_html( get_search_query( false ) ); ?>


扩展阅读:

the_search_query函数位于wp-includes/general-template.php文件中。

官方地址:https://developer.wordpress.org/reference/functions/the_search_query/

发表评论

暂无评论,抢个沙发...

客服 工单