在wordpress导航栏添加外部链接方法:
首选创建linkto.php做为模板文件
代码如下
1 2 3 4 5 6 7 8 9 10 |
<?php /*Template Name: linkto*/ 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中所使用的主题的根目录下(如/wp-content/themes/你所用主题)。
最后按照正常方式创建一个页面,并在创建页面底部的 “页面模板“选择linkto。在页面中,除了你的链接,其它什么内容都不要填,然后发布页面即可。