Redirect When Search Query is an Exact Title in Wo

2019-09-04 05:34发布

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

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

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

1条回答
戒情不戒烟
2楼-- · 2019-09-04 06:04

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);
    }
}

?>

or

<?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; 
          }
    }
?>
查看更多
登录 后发表回答