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
