当搜索查询是 Wordpress 中的确切标题时重定向 [英] Redirect When Search Query is an Exact Title in Wordpress

查看:27
本文介绍了当搜索查询是 Wordpress 中的确切标题时重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Wordpress 中有两个帖子标题:

I have two post titles in Wordpress:

post_title: gröband 
permalink: www.example.com/groband.html

post_title: groband
permalink: www.example.com/groband-2.html

我想在搜索查询是gröband"时重定向到www.example.com/groband.html

I want redirect when search query is "gröband" to www.example.com/groband.html

如果搜索查询是groband",则重定向到www.example.com/groband-2.html

if search query is "groband" redirect to www.example.com/groband-2.html

推荐答案

在主题编辑器中编辑您的搜索模板并添加此顶部

Edit your search template in theme editor and add this top

<?php

if(isset($_GET['s'])){
$url ="";
switch($_GET['s']){
case 'gröband': 
      $url = "http://www.example.com/groband.html"; 
     break;
case 'groband': 
    $url = "www.example.com/groband-2.html";
      break; 
}
if(!empty($url)){
    header("Location: ".$url);
    }
}

?>

<?php
    if(isset($_GET['s'])){
    switch($_GET['s']){
    case 'gröband': 
         header("Location:http://www.example.com/groband.html"); 
         break;
    case 'groband': 
         header("Location:http://www.example.com/groband-2.html");
         break; 
          }
    }
?>

这篇关于当搜索查询是 Wordpress 中的确切标题时重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆