Add read more button with the_content() function

Its quite simple to add the Read More button with the_content() function, the_content() function is displaying the content of the current post but if its find the tag into the post then its only display the upper content of this tag into the single post. This is how it looks like in the template part.

<?php the_content( __( 'Continue reading <span class="meta-nav"></span>', 'twentytwelve' ) ); ?>

What we have to do is, just make the_content() function blank and add the button function under the_content() function into your template file. Take a look on the codes.

the_content("");
if( ! is_single() ):
echo read_more_button();
endif;

 

Now go the your themes functions.php file and add the following function that we have used to display the button, but wait a minute. I think you have question that why i am using the if( ! is_single() ) condition? This is because we want the read more button on the blog page not the full post page. So here we created the open the functions.php file and added the following function:

function read_more_button() {
    global $post;
    return '<div id="" class="btn"></div>';
}

 

Posted by Jogesh Sharma

Jogesh Sharma is a web developer and blogger who loves all the things design and the technology, He love all the things having to do with PHP, WordPress, Joomla, Magento, Durpal, Codeigniter, jQuery, HTML5 etc. He is the author of this blog.