AI 助手设置WordPress 无插件完美实现文章内外链改写跳转参数说明:10_2_1656126428,第一段是文章 ID,第二段是文章内外链 ID,第三段是时间戳为什么要加入一个时间戳?在测试中,修改文章内链接时, 跳转页面 有一段时间缓存,时间戳是实时的,防止因为缓存而未能及时修改文章内链接!(其实,可能也不需要)首先在模板 文件夹内新建一个页面模板 page-go.php,代码如下1post_content);//get_post($postid)->post_content 通过 ID 获取文章内容,alllink()//提取文10$url=$links[$jumpid];11Header( "HTTP/1.1 301 Moved Permanently" );12Header( "Location: ".$url );13?>其次,在 functions.php 中修改改写链接,代码:1function alllink($content){AI 助手2global $post;3$pattern="/
/";4preg_match_all($pattern, $content, $matches);5if(!empty($matches[1])){6$link=$matches[1];7$i=0;8if(isset($_GET["e"])){9return $link;10}else{11foreach($link as $url){12$content=str_ireplace($url,get_bloginfo("url").'/go?e='.$post->ID.'_'.$i.'_'.time(),$content);13$i++;14}15return $content;16}1718}19return false;20}21add_filter( 'the_content', 'alllink' );链接改写成功,不用插件,不操作数据库改写外链格式1/2