WordPress文章末端如何添加本文URL?WP原文鏈接PHP代碼

如何在WordPress中每篇文章的末尾添加原文鏈接

WordPress文章末端如何添加本文URL?WP原文鏈接PHP代碼

使用WordPress建立站的朋友,若想要加上“原創文章若轉載,請註明本文鏈接:”,實際上非常簡單。

這裡就分享2種在WordPress文末添加本文鏈接URL的方法。

?‍?一、修改文章頁面模板single.php

在WordPress主題模板文件中,打開single.php,搜索以下PHP代碼:

<?php the_content(); ?>

這行PHP代碼的下面,添加以下PHP代碼▼

<p>原创文章如转载,请注明本文链接: <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_permalink(); ?></a></p>
  • 然後,保存更新,這樣就可以了。

?‍?二、添加PHP代碼到function.php文件

建議這種方法,不僅可以添加到博客日誌頁面的鏈接,包括feed也是可以。

打開主題文件夾中的function.php文件,並在最後添加以下PHP代碼(複製和粘貼時請注意中文和英文標點符號):

<?php
function feed_copyright($content) {
if(is_single() or is_feed() or is_page()) {
$content.= '<div>    » 本文来自:<a title="陈沩亮博客" href="https://www.chenweiliang.com/" target="_blank">陈沩亮博客</a> » <a rel="bookmark" title="'.get_the_title().'" href="'.get_permalink().'" target="_blank">《'.get_the_title().'》</a></div>';
$content.= '<div>    » 本文链接地址:<a rel="bookmark" title="'.get_the_title().'" href="'.get_permalink().'" target="_blank">'.get_permalink().'</a> »英雄不问来路,转载请注明出处,谢谢。</div>';
$content.= '<div>    » 有话想说:<a title="给我留言" href="'.get_permalink().'#respond" target="_blank">那就赶紧去给我留言吧.</a></div>';
$content.= '<div>    » 欢迎加入陈沩亮博客的 Telegram 频道:<a rel="external nofollow" title="点此加入陈沩亮博客的 Telegram 频道" href="" target="_blank">https://www.chenweiliang.com/go/tgchannel</a></div>';
}
return $content;
}
add_filter ('the_content', 'feed_copyright');
?>
  • 請根據你的WordPress博客做修改。

希望陳溈亮博客( https://www.chenweiliang.com/ ) 分享的《WordPress文章末端如何添加本文URL?WP原文鏈接PHP代碼》,對您有幫助。

歡迎分享本文鏈接:https://www.chenweiliang.com/cwl-1498.html

歡迎加入陳溈亮博客的Telegram 頻道,獲取最新更新!

🔔 率先在頻道置頂目錄獲取寶貴的《ChatGPT 內容行銷AI 工具使用指南》! 🌟
📚 這份指南蘊含價值巨大,🌟難逢的機遇,切勿錯失良機! ⏰⌛💨
喜歡就分享和按贊!
您的分享和按贊,是我們持續的動力!

 

發表評論

您的電子郵箱地址不會被公開。 必填項已用 * 標註

滾動到頂部