• Get In Touch
June 15, 2018

How To Add A Load More Posts Button In WordPress

Using Wordpress? Get our lightening fast Wordpress Optimised Hosting.
Get Wordpress Hosting

Many popular platforms allow users to load more posts when they reach the bottom of the page. In this article, we will show you how to easily add a load more posts button to your own website in WordPress.

Why Should I Add A Load More Posts Button?

Many blogs use a simple ‘Older posts’ navigation link at the end of their home, blog, or archive pages. Some websites may even use numeric page navigation which adds more context.

However, there are some type of websites that can benefit immensely from an infinite scroll or a load more posts button. Some examples include photography websites, lists, and viral content websites.

Instead of loading a whole new page, a ‘load more posts’ button works kind of like an infinite scroll. It uses JavaScript to quickly fetch the next set of content. This can improve the user experience and gives them a chance to view more of your content.

Now let’s take a look at how easy it is to actually add a load more posts button in WordPress.

Adding The More Posts Button To Your Website

The first thing we would recommend doing is downloading and adding the Ajax plugin to your website.

Once activated, the plugin will add a new menu item labelled ‘Ajax Load More’ to your WordPress admin menu. Click on it and you’ll be taken to the plugins settings page.

Here, you can change settings such as the colour of your button, or change over from a load more posts button to something else, like an infinite scroll for example.

Next, you will need to visit the Ajax Load More > Repeater Template page to add your template for displaying posts. The plugin comes with a basic template containing the WordPress loop to display posts. However, if it does not match your theme it may look out of place on your website.

To fix this, you need to copy the code your theme uses to display posts on the index, archive, and blog pages. Normally, this code is located in the template-parts folder of your theme. In that folder, you will see templates to display different content. For example content-page.php, content-search.php, and more.

You will be looking for the generic content.php template.

Once you find that code, you’ll need to paste it inside the Repeater Templates field in plugin settings. Next, you need to go to the Ajax Load More > Shortcode Builder page to generate a shortcode.

First, you will need to select the container type. If you are unsure, just look at the template you copied earlier. Most modern themes use the;<div> element.

After that scroll down to the button labels section. Here you can change the text that appears on the button. By default, the plugin uses ‘Older Posts’, but you can change that to a ‘Load more posts’ or anything else you want.

Your shortcode is now ready to be used. In the right column, you will see the shortcode output. Go ahead and copy the shortcode and paste it into a text editor, as you’ll need it in the next step.

Adding The Load More Posts Button To Your Theme

This part of the tutorial requires you to add code into your WordPress theme files. Don’t forget to backup your WordPress theme and website before making any changes.

You will need to find the template files where you want to add the load more posts button in your theme. Depending on how your theme is organized, usually, these files are index.php, archives.php, categories.php, etc.

You will need to add the shortcode you copied earlier into your theme right after the endwhile; tag. Since we are adding the shortcode in a theme file, we will need to add it inside the do_shortcode function, like this:

echo do_shortcode('[ajax_load_more container_type="div" post_type="post"]');           

You can now save the changes to your website and visit it in action to see the ‘Load more posts’ work it’s magic!

Using Wordpress? Get our lightening fast Wordpress Optimised Hosting.
Get Wordpress Hosting

Share this Article!

Related Posts

5 Website Hosting Solution Trends for 2022 and Beyond

5 Website Hosting Solution Trends for 2022 and Beyond

Looking for the right web hosting solution for your website can be an intimidating task. Options nowadays are more diversified than ever, and each year brings new developments in the web hosting market. If you have no clue of what to look out for, you can find yourself overwhelmed with the choices. Hence, you must […]

64 Content Marketing Statistics Demonstrating the Power of Content

64 Content Marketing Statistics Demonstrating the Power of Content

Content marketing continues to be one of the most valuable tools for today’s online businesses. With content, you can improve your chances of reaching your target audience, boost your search engine standing, and even unlock new opportunities for sales. The more content you produce, the more you can strengthen your domain authority, demonstrate your thought […]

53 User Experience Stats for 2022

53 User Experience Stats for 2022

User Experience (UX) is one of the most crucial factors to consider in web design. As the number of websites and applications in the world today continues to accelerate, businesses are under more pressure than ever to impress customers straight away. If a user visits your website and finds slow-loading pages, clunky navigation, or errors, […]

How to increase the memory limit in WordPress

How to increase the memory limit in WordPress

Do you need to increase the memory limit in WordPress? Getting an error about memory Exhausted? The memory limit is one of the most common WordPress errors as the default limit of memory in WordPress is only set to 64mb! But there’s good news! The Memory Exhausted error is one of the easiest to fix […]

All in One WordPress Migration Vulnerability

All in One WordPress Migration Vulnerability

A vulnerability has been discovered in the “All In One WordPress Migration” WordPress plugin. All versions earlier than, and including 6.97 contain a vulnerability which allows Cross-Site Scripting (XSS). With over 2 million active installations, this vulnerability has the potential to be high impact, however, this is lessened by the nature of the vulnerability, which […]