在Wordpress现有主题下,添加新的页面模板。每个Wordpress主题都有默认的主题模板,但也可以在该主题下定制自己的页面模板。现在我在使用的主题目录下,新建文件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]) header('Location: '.$matches[0]); else echo 'Enter a URL into your page body text.'; } ?>
保存该文件。然后到Wordpress后台,添加新页面,在页面内容中添加你要连接到的页面地址,如Http://photo.dongv.com
然后再编辑页面的右下角,选择页面模板为“Redirect”,并保存页面即可。