How to add the URL of this article at the end of a WordPress article? WP original link PHP code

How toWordPressAdd a link to the original text at the end of each article in?

How to add the URL of this article at the end of a WordPress article? WP original link PHP code

使用WordPress websitefriends of , if you want to add "If the original article is reproduced, please indicate the link to this article:”, which is actually quite simple.

Here are 2 ways to add a link URL to this article at the end of your WordPress post.

?‍?First, modify the article page template single.php

In the WordPress theme template file, open single.php and search for the following PHP code:

<?php the_content(); ?>

Below this line of PHP code, add the following PHP code▼

<p>原创文章如转载,请注明本文链接: <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_permalink(); ?></a></p>
  • Then, save the update and that's it.

?‍?Second, add the PHP code to the function.php file

This method is recommended, not only to add links to blog log pages, but also to include feeds.

Open the function.php file in the theme folder and add the following PHP code at the end (note the Chinese and English punctuation when copying and pasting):

<?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');
?>
  • Please modify it according to your WordPress blog.

Hope Chen Weiliang Blog ( https://www.chenweiliang.com/ ) shared "How to add the URL of this article at the end of a WordPress article? WP original link PHP code", which is helpful to you.

Welcome to share the link of this article:https://www.chenweiliang.com/cwl-1498.html

Welcome to the Telegram channel of Chen Weiliang's blog to get the latest updates!

🔔 Be the first to get the valuable "ChatGPT Content Marketing AI Tool Usage Guide" in the channel top directory! 🌟
📚 This guide contains huge value, 🌟This is a rare opportunity, don’t miss it! ⏰⌛💨
Share and like if you like!
Your sharing and likes are our continuous motivation!

 

Comment

Your email address will not be published. Required fields * Callout

scroll to top