Warning: session_start(): Unable to clear session lock record in /www/wwwroot/reaff.com/wp-content/themes/Autumn-Pro/functions.php on line 5

Warning: session_start(): Failed to read session data: memcached (path: 127.0.0.1:11211) in /www/wwwroot/reaff.com/wp-content/themes/Autumn-Pro/functions.php on line 5
wordpress搜索只有一篇日志直接打开 – 王板汪之家

wordpress搜索只有一篇日志直接打开

教程

  1. /**当搜索结果只有一篇 直接打开搜索的这篇日志**/
  2. add_action(‘template_redirect’, ‘wpjam_redirect_single_post’);
  3. function wpjam_redirect_single_post() {
  4. if (is_search()) {
  5. global $wp_query;
  6. if ($wp_query->post_count == 1) {
  7. wp_redirect( get_permalink( $wp_query->posts[‘0’]->ID ) );
  8. }
  9. }
  10. }

注意:以上代码请添加到主题更目录functions.php文件里面去

相关推荐