wordpress中如何將新建頁面指向自定義的url


1,自定義模板文件:

    空間源文件中,當前主題文件夾下,新建一個php文件,名字自定義,如:redirect.php

2,打開redirect.php,輸入代碼:

<?php /*Template Name: Redirect*/

if(have_posts()) {
the_post();
$pattern ='@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@';
preg_match($pattern, get_the_excerpt(), $matches);
if ($matches[0]) {
//echo $matches[0];
header("Location:$matches[0]");
}else{
echo 'Enter a URL into your page body text.';
}
}
?>

3,進入wp后台

  頁面——新建頁面——內容中直接寫url——模板 選擇上一步創建的Redirect

ok,game over


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM