1. Home
  2. Knowledge Base
  3. Customizations
  4. PHP Functions
  5. How to Disable Blog Post Page Autoload and Show a “Load More” Button Instead

How to Disable Blog Post Page Autoload and Show a “Load More” Button Instead

Introduction

By default, BuddyBoss automatically loads blog posts on the blog page as the user scrolls or navigates. You can change this behavior by adding a custom function that replaces the autoload feature with a “Load More” button. This gives your users the option to manually load additional posts instead of infinite scrolling. This guide explains how you can disable blog post page autoload and show a “Load More” button instead.

Custom Workaround

Before proceeding, make sure you have a complete site backup.

  1. Go to Appearance > Theme Editor in your WordPress admin dashboard.
  2. Under Select theme to edit, choose your active theme (preferably a BuddyBoss Child Theme), then click Select.
  3. From the Theme Files list, open Theme Functions (functions.php).
  4. Add the following code just before the closing PHP tag (?>):

/** 

 * Custom Pagination: Replace autoload with “Load More” button 

 */

function buddyboss_pagination() {

    global $paged, $wp_query;

    $max_page = 0;

    if ( ! $max_page ) {

        $max_page = $wp_query->max_num_pages;

    }

    if ( ! $paged ) {

        $paged = 1; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited

    }

    $nextpage = intval( $paged ) + 1;

    if ( is_front_page() || is_home() ) {

        $template = ‘home’;

    } elseif ( is_category() ) {

        $template = ‘category’;

    } elseif ( is_search() ) {

        $template = ‘search’;

    } else {

        $template = ‘archive’;

    }

    $class = ”;

    $label = __( ‘Load More’, ‘buddyboss-theme’ );

    if ( ! is_single() && ( $nextpage <= $max_page ) ) {

        $attr = ‘data-page=’ . $nextpage . ‘ data-template=’ . $template; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped

        echo ‘<div class=”bb-pagination pagination-below”><a class=”button-load-more-posts’ . esc_attr( $class ) . ‘” href=”‘ . esc_url( next_posts( $max_page, false ) ) . “\” esc_attr( $attr )>” . esc_html( $label ) . ‘</a></div>’;

    }

}

  1. Click Update File to save the changes.

Note: Modifications are typically considered custom work, but we are making an exception in this case. Please review the BuddyBoss Support Policy.

Troubleshooting and FAQs

Q: The “Load More” button does not appear.
A: Ensure that you are on a blog or archive page with more posts than the posts-per-page setting. Also, clear any caching plugins.

Q: Will this affect mobile or tablet devices?
A: No. The button appears on all devices, replacing the autoload functionality.

Q: Can I revert this change easily?
A: Yes. Remove or comment out the code from functions.php and save the file.

Was this article helpful?

Related Articles

Subscribe to Our Newsletter

Stay In Touch

Subscribe to our Newsletter, and we’ll send you the latest news from BuddyBoss

  • This field is hidden when viewing the form
  • This field is for validation purposes and should be left unchanged.

To speak to our Agency consultant, fill in the form found at our Contact Page.

  • Get Started

    Enter your name and email address to get started with your project...

  • This field is for validation purposes and should be left unchanged.