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