I sometimes need to copy the posts to somewhere for easy sharing purpose and at the end of the post, I will point out the URL for the original article. And I find it not so convenient as I have to manually copy the URL and paste. The following trick can solve this problem easily. At the end of each posts/pages, the link for the current page will be appended.
Edit the template file functions.php and append the following PHP code to the end of file.
1 2 3 4 5 6 7 8 9 | // helloacm.com add_filter( 'the_content', 'insert_post' ); function insert_post( $content ) { $post_id = get_the_ID(); $link = get_permalink($post_id); $title = get_the_title($post_id); return $content.'<BR/>Share this URL:<a title="'.$title.'" href="'.$link.'"><B>'.$link.'</B></a>'; } |
// helloacm.com add_filter( 'the_content', 'insert_post' ); function insert_post( $content ) { $post_id = get_the_ID(); $link = get_permalink($post_id); $title = get_the_title($post_id); return $content.'<BR/>Share this URL:<a title="'.$title.'" href="'.$link.'"><B>'.$link.'</B></a>'; }
It is very straightforward and if you know English you understand what it means. The wordpress is so powerful because it already provides so many handy functions such as get_the_ID() which obtains the ID of the current page/post,get_permalink() that returns the URL of the page/posts,and get_the_title() gets the title of the pages/posts. These two functions have the optional parameter [post id] which if omitted will return the current page/posts.
–EOF (The Ultimate Computing & Technology Blog) —
Last Post: How to Remove Annoying Setup Dialog When Microsoft Office 2000 startup Due to Problematic Add-ons?
Next Post: How to Setup HHVM on the Ubuntu VPS?