我是立即将“标识”做为文章内容关键字的,那么做也是因为便捷编码完成WordPress全自动关键字keywords与叙述description。但如此经常是一个“标识”才相匹配一篇文章,为了更好地提升客户体验,我们可以在WordPress 标识网页页面仅有一篇文章时自动跳转到该文章内容。
将下边的编码加上到主题风格的functions.php 文档下:
- add_action(‘template_redirect’, ‘tag_redirect_single_post’);
- function tag_redirect_single_post() {
- if (is_tag()) {
- global $wp_query;
- if ($wp_query->post_count == 1) {
- wp_redirect( get_permalink( $wp_query->posts[‘0’]->ID ) );
- }
- }
- }
编码创作者不明。高級一点的,可以将此与《WordPress内置搜索结果只有一篇文章时自动跳转到该文章》一文的编码合拼为如下所示:
- add_action(‘template_redirect’, ‘redirect_single_post’);
- function redirect_single_post() {
- if (is_tag() || is_search()) {
- global $wp_query;
- if ($wp_query->post_count == 1) {
- wp_redirect( get_permalink( $wp_query->posts[‘0’]->ID ) );
- }
- }
申明:
本文章内容转自DeveWork (转截此文章内容仅用以交流学习仅用,若有质疑请联络本网站删掉,感谢!)