Read More Link for WordPress Page

What is it about?

To generate a Read More… link in WordPress post, you have to write <!–more–> (in HTML view of WordPress wysiwyg text editor) in place where you want to display the link as shown below:


How to add read more link in wordpress post

Now I want to point out that this technique will not work in wordpress pages. For example, you create a CMS website in WordPress and you created a custom home page.
Now suppose that you fetched the latest post from News category on the home page. The latest post’s Read More… link will not appear on the home page and it will display the complete post.

In this post you will learn how to make Read More… link to work in WordPress pages.

The Solution

Step 1

Declare $more variable global on top of you custom WordPress page (I mostly declare it at the top of header.php) as shown below:

global $more;

Step 2

Now initialize $more to zero before calling the_content() function as shown below:

// --- fetch latest News post --- //



// fetch only 1 post from News category

query_posts( 'showposts=1&#038;category_name=news' );



if( have_posts() ) {

        while( have_posts() ) {

                the_post();

                $blog_title = get_the_title( get_the_ID() );

                

                <strong>$more = 0; //this is required for Read More link to work on pages</strong>

                

                $blog_content = get_the_content( 'Read More...' );

                $blog_link = get_permalink();

        } //end while

        

        wp_reset_query();

} //end if

That’s it! Now your read more links will work in custom pages as well.


comments powered by Disqus