A easy way to add copyright information automatically into post(English Version英文版)


Several weeks ago, I decided to write about two blog posts every day. I used to write copyright information manually in the post. Apparently, it's better to let the machine do this type of trivial work automatically. So, I searched the plugins to try to find a convenient one. Indeed, I found the plugin named "add post URL" which is able to help the author to insert copyright information into the post. When I clicked the 'DETAIL' button to see more. A warning message popped up: "This plugin has not been tested with your current version of WordPress". I was scared. Because I once had a bad experience about how untested plugin ruined my wordpress as a whole. So, the option of using plugin to insert copyright information was ruled out.


Then, I tried to modify wordpress's sourcecode by myself. I googled some related post taking about how to do this kind of work. One article suggested to modify the single.php file, which I am not very sure if the file name will change depends on different themes you use. I reckon the file name will be like the style of "single.php", more or less. Now, you locate the following code in single.php.


<?php the_content(); ?>

Pagination for Multi-page posts
~~~ –>
<?php wp_link_pages('before=<p class="multi-page">Pages:&after=</p>'); // if this is a multipage post then show the navigation ?>
As long as you've found it, insert code that generate copyright information below the line <?php the_content(); ?>. Unfortunately, many people will soon find this is not going to work. Since many other plugins has already add texts into the post content. Take my blog for example, I use the plugin to automatically generate related posts list at the bottom of every post. So, in this way, copyright information will be put right below the related posts list, rather than expected right below the real post content. It is definitely undesirable. 
I did google more and found a solution. One article suggest to modify function.php and add a customer defined function to replace the original the_content() function in the single.php file. I read the code and found it's not easy to comprehend for a normal person who are not familiar with wordpress's code. I didn't understand the parameters transferred to the function at least. What is more, I greatly doubted this kind of solution will collide with my plugin generating related posts list.
Everything seemed to get stuck. I went out to have my supper and have some kind of fresh air. When I returned to the front of the computer. I suddenly figured out a perfect solution of add copyright info into my post without using plugin and heavy code. The idea is described as the following steps:
step 1: when you are composing your article, type some kind of special and simple string in the place where you expect to show up the copyright information. Take my blog for exambple, I type "COPYRIGHT   WWW.DOGEYE.NET" at the tail of every post.
step 2: Using php code to replace the special string to anything relatively verbose in the time when the post will be showing.
Isn't it a brilliant, simple and flexible idea.
To put this idea into real. You must make it clear that the two function the_content() and get_the_content() behaves differently. When the function the_content() is invoked, the content of the post is being printed out. get_the_content() is different, this function return the article text as a string return value. As you have got this point clear, you should comprehend the following code, which replace the the_content() function with get_the_content() function.
$thread_content = get_the_content();             // variable $thread_content holds the post content.
$thread_permalink = get_permalink();              // get the current post's permanent link.
$thread_title = get_the_title();                         // get the current post's title.
$dogeye_copyright = "<p style='font-weight:bold';><span>Original Article created by</span> <a href='http://ykyi.net' target='_blank'>DogEye.NET</a><br/><span>Repost is only allowed if original URL is reserved.</span><br/><a href=\"$thread_permalink\" target='_blank'>$thread_title<br/>$thread_permalink</a></p>";       // the HTML code that claiming copyright
// The following code change the simple string "COPYRIGHT  WWW.DOGEYE.NET" with more verbose HTML code.
$thread_content = str_replace('COPYRIGHT  WWW.DOGEYE.NET', $dogeye_copyright, $thread_content);
echo $thread_content;    // print out the modified content.
I suppose this piece of code snippet is easy to comprehend with comments. If you think it is useful, you could replace the site-specified string with your version. Hope this post will be helpful.