WordPress文案外边链接清除
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">“</span></strong><span style="color: black;"> <span style="color: black;">保持</span>分享<span style="color: black;">优秀</span>内容,<span style="color: black;">重点</span>为Python、SEO、WordPress以及综合应用<span style="color: black;">关联</span>,让工作批量化、自动化,助你更<span style="color: black;">有效</span>完成项目,欢迎你的关注。<strong style="color: blue;"><span style="color: black;">”</span></strong></span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">文案</span>目录</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">操作流程</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">清除<span style="color: black;">所有</span><span style="color: black;">文案</span><span style="color: black;">外边</span>链接代码</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">按照</span>搜索内容清除<span style="color: black;">外边</span>链接代码</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">运用</span>之后</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">WordPress<span style="color: black;">文案</span><span style="color: black;">外边</span>链接清除<span style="color: black;">办法</span>分享,有时候<span style="color: black;">咱们</span>采集<span style="color: black;">或</span>引用了其他<span style="color: black;">文案</span>,有时候会忘记去除<span style="color: black;">外边</span>链接<span style="color: black;">或</span>是采集规则<span style="color: black;">由于</span><span style="color: black;">各样</span>未知<span style="color: black;">原由</span>未处理干净a标签,<span style="color: black;">咱们</span>就<span style="color: black;">能够</span>用<span style="color: black;">倘若</span><span style="color: black;">办法</span>对WordPress<span style="color: black;">文案</span>的<span style="color: black;">外边</span>链接进行清除。</p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;">操作流程</h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">首要</span>,备份了数据库,以防止意外<span style="color: black;">状况</span><span style="color: black;">出现</span>。</strong></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">登录到你的WordPress后台。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在左侧的导航菜单中,找到并点击“外观”选项,<span style="color: black;">而后</span><span style="color: black;">选取</span>“编辑主题”子菜单。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在编辑主题文件的页面,找到并点击“functions.php”文件。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在functions.php文件的末尾添加以下代码:</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">将代码中的www.linfengnet.com改为自己的域名</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">重视</span>在域名中的.符号前面加一个 英文的\符号。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">添加完之后等一会你再看就会<span style="color: black;">发掘</span><span style="color: black;">文案</span>中的<span style="color: black;">外边</span>链接就被清除了。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">举荐</span>你<span style="color: black;">运用</span>WPCode 代码片段插件</strong><span style="color: black;">,你<span style="color: black;">能够</span>直接将下述代码添加为一个新的代码片段开启,关于这个插件的介绍<span style="color: black;">举荐</span>你看我之前<span style="color: black;">文案</span>:</span><a style="color: black;">WordPress代码片段插件 WPCode</a><span style="color: black;">。</span></p>
<h3 style="color: black; text-align: left; margin-bottom: 10px;">清除<span style="color: black;">所有</span><span style="color: black;">文案</span><span style="color: black;">外边</span>链接代码</h3>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">倘若</span><span style="color: black;">文案</span>数量少,<span style="color: black;">能够</span>直接<span style="color: black;">运用</span>下面这个代码,会清除所有<span style="color: black;">文案</span>的<span style="color: black;">外边</span>链接。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">// <span style="color: black;">重视</span>备份数据库哦!!!</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">function</span><span style="color: black;">remove_external_links</span><span style="color: black;">()</span><span style="color: black;">{</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"> $args </span><span style="color: black;">=</span><span style="color: black;"> array</span><span style="color: black;">(</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">post_type</span><span style="color: black;">=></span><span style="color: black;">post</span><span style="color: black;">,</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">posts_per_page</span><span style="color: black;">=></span><span style="color: black;">-</span><span style="color: black;">1</span><span style="color: black;">,</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">);</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"> $query </span><span style="color: black;">=</span><span style="color: black;">new</span><span style="color: black;"> WP_Query</span><span style="color: black;">(</span><span style="color: black;">$args</span><span style="color: black;">);</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">if</span><span style="color: black;">(</span><span style="color: black;">$query</span><span style="color: black;">-></span><span style="color: black;">have_posts</span><span style="color: black;">())</span><span style="color: black;">{</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">while</span><span style="color: black;">(</span><span style="color: black;">$query</span><span style="color: black;">-></span><span style="color: black;">have_posts</span><span style="color: black;">())</span><span style="color: black;">{</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"> $query</span><span style="color: black;">-></span><span style="color: black;">the_post</span><span style="color: black;">();</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"> $content </span><span style="color: black;">=</span><span style="color: black;"> get_the_content</span><span style="color: black;">();</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"> $updated_content </span><span style="color: black;">=</span><span style="color: black;"> preg_replace</span><span style="color: black;">(</span><span style="color: black;">/<a.*?href=["\](http?:\/\/(?!www\.linfengnet\.com)[^"\]*)["\].*?>(.*?)<\/a>/i</span><span style="color: black;">,</span><span style="color: black;">$2</span><span style="color: black;">,</span><span style="color: black;"> $content</span><span style="color: black;">);</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">if</span><span style="color: black;">(</span><span style="color: black;">$content </span><span style="color: black;">!==</span><span style="color: black;"> $updated_content</span><span style="color: black;">)</span><span style="color: black;">{</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"> $post_id </span><span style="color: black;">=</span><span style="color: black;"> get_the_ID</span><span style="color: black;">();</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"> $post_data </span><span style="color: black;">=</span><span style="color: black;"> array</span><span style="color: black;">(</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">ID</span><span style="color: black;">=></span><span style="color: black;"> $post_id</span><span style="color: black;">,</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">post_content</span><span style="color: black;">=></span><span style="color: black;"> $updated_content</span><span style="color: black;">,</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">);</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"> wp_update_post</span><span style="color: black;">(</span><span style="color: black;">$post_data</span><span style="color: black;">);</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">}</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">}</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">}</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"> wp_reset_postdata</span><span style="color: black;">();</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">}</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">add_action</span><span style="color: black;">(</span><span style="color: black;">init</span><span style="color: black;">,</span><span style="color: black;">remove_external_links</span><span style="color: black;">);</span></p>
<h3 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">按照</span>搜索内容清除<span style="color: black;">外边</span>链接代码</h3>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">倘若</span>在<span style="color: black;">咱们</span><span style="color: black;">文案</span>数量非常多的<span style="color: black;">状况</span>下,<span style="color: black;">运用</span>上面清除<span style="color: black;">所有</span><span style="color: black;">文案</span>的代码,可能会<span style="color: black;">引起</span>占用服务器性能比较多,网站卡顿等<span style="color: black;">状况</span>,<span style="color: black;">咱们</span><span style="color: black;">能够</span><span style="color: black;">经过</span>搜索的方式,搜索要清除的<span style="color: black;">外边</span>链接。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">例如</span>你的<span style="color: black;">文案</span>中存在www.baidu.com的外链,你就把www.baidu.com替换your_search_query,<span style="color: black;">而后</span>程序会搜索到存在www.baidu.com的<span style="color: black;">文案</span>,<span style="color: black;">而后</span>把它们存在的所有<span style="color: black;">外边</span>链接都去除。不单单是链接,你搜索其他特定<span style="color: black;">重要</span>词去清除<span style="color: black;">亦</span>是<span style="color: black;">能够</span>的。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">和上面清除<span style="color: black;">所有</span>文章中的代码<span style="color: black;">同样</span>,记得把remove_external_links函数里面的正则域名替换为自己的(<span style="color: black;">这般</span>就除了自己域名以外的链接都清空)。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">$args </span><span style="color: black;">=</span><span style="color: black;"> array</span><span style="color: black;">(</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">s</span><span style="color: black;">=></span><span style="color: black;">your_search_query</span><span style="color: black;">,</span><span style="color: black;">// 替换为你的搜索<span style="color: black;">重要</span>字</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">post_type</span><span style="color: black;">=></span><span style="color: black;">post</span><span style="color: black;">,</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">posts_per_page</span><span style="color: black;">=></span><span style="color: black;">-</span><span style="color: black;">1</span><span style="color: black;">,</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">fields</span><span style="color: black;">=></span><span style="color: black;">ids</span><span style="color: black;">,</span><span style="color: black;">// 只获取<span style="color: black;">文案</span>ID</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">);</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">$query </span><span style="color: black;">=</span><span style="color: black;">new</span><span style="color: black;"> WP_Query</span><span style="color: black;">(</span><span style="color: black;">$args</span><span style="color: black;">);</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">$external_Links </span><span style="color: black;">=</span><span style="color: black;"> array</span><span style="color: black;">();</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">if</span><span style="color: black;">(</span><span style="color: black;">$query</span><span style="color: black;">-></span><span style="color: black;">have_posts</span><span style="color: black;">())</span><span style="color: black;">{</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"> $post_ids </span><span style="color: black;">=</span><span style="color: black;"> $query</span><span style="color: black;">-></span><span style="color: black;">posts</span><span style="color: black;">;</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"> wp_reset_postdata</span><span style="color: black;">();</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">// 将得到的id加入数组</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"> $external_Links </span><span style="color: black;">=</span><span style="color: black;"> $post_ids</span><span style="color: black;">;</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"> echo </span><span style="color: black;"><span style="color: black;">文案</span>ID已<span style="color: black;">保留</span>到数组中。</span><span style="color: black;">;</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">}</span><span style="color: black;">else</span><span style="color: black;">{</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"> echo </span><span style="color: black;"><span style="color: black;">无</span>找到匹配的<span style="color: black;">文案</span>。</span><span style="color: black;">;</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">}</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">function</span><span style="color: black;"> remove_external_links</span><span style="color: black;">()</span><span style="color: black;">{</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">global</span><span style="color: black;"> $external_Links</span><span style="color: black;">;</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">foreach</span><span style="color: black;">(</span><span style="color: black;">$external_Links </span><span style="color: black;">as</span><span style="color: black;">$post_id</span><span style="color: black;">)</span><span style="color: black;">{</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"> $post </span><span style="color: black;">=</span><span style="color: black;"> get_post</span><span style="color: black;">(</span><span style="color: black;">$post_id</span><span style="color: black;">);</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"> $content </span><span style="color: black;">=</span><span style="color: black;"> $post</span><span style="color: black;">-></span><span style="color: black;">post_content</span><span style="color: black;">;</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"> $updated_content </span><span style="color: black;">=</span><span style="color: black;"> preg_replace</span><span style="color: black;">(</span><span style="color: black;">/<a.*?href=["\](http?:\/\/(?!www\.linfengnet\.com)[^"\]*)["\].*?>(.*?)<\/a>/i</span><span style="color: black;">,</span><span style="color: black;">$2</span><span style="color: black;">,</span><span style="color: black;"> $content</span><span style="color: black;">);</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">if</span><span style="color: black;">(</span><span style="color: black;">$content </span><span style="color: black;">!==</span><span style="color: black;"> $updated_content</span><span style="color: black;">)</span><span style="color: black;">{</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"> $post_data </span><span style="color: black;">=</span><span style="color: black;"> array</span><span style="color: black;">(</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">ID</span><span style="color: black;">=></span><span style="color: black;"> $post_id</span><span style="color: black;">,</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">post_content</span><span style="color: black;">=></span><span style="color: black;"> $updated_content</span><span style="color: black;">,</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">);</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"> wp_update_post</span><span style="color: black;">(</span><span style="color: black;">$post_data</span><span style="color: black;">);</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">}</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">}</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">}</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">add_action</span><span style="color: black;">(</span><span style="color: black;">init</span><span style="color: black;">,</span><span style="color: black;">remove_external_links</span><span style="color: black;">);</span></p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">运用</span>之后</h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">上面代码<span style="color: black;">运用</span>完之后,请将它们从你的functions.php文件中删除<span style="color: black;">或</span>是从WPCode插件中关闭<span style="color: black;">就可</span>。</p>
<h2 style="color: black; text-align: left; margin-bottom: 10px;">仅清除失效链接</h2>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">倘若</span>是仅<span style="color: black;">必须</span>清除失效链接,<span style="color: black;">那样</span><span style="color: black;">举荐</span>你<span style="color: black;">运用</span>之前的<span style="color: black;">咱们</span>分享的Broken Link Checker插件,详情请你看:</p>WordPress<span style="color: black;">文案</span>失效<span style="color: black;">照片</span>/链接检测插件<span style="color: black;">举荐</span>:Broken Link Checker<span style="color: black;">https://www.linfengnet.com/wordpress-plugin/2790.html</span>
</div>
你的见解真是独到,让我受益匪浅。 楼主果然英明!不得不赞美你一下! 哈哈、笑死我了、太搞笑了吧等。 你的见解真是独到,让我受益匪浅。
页:
[1]