Back to Community

How to Fix Missing Pagination in the Shortcodes Ultimate Posts Shortcode

Content

One of the most powerful features of the Shortcodes Ultimate plugin is the [su_posts] shortcode, which allows you to display a list of posts anywhere on your site. However, a common frustration arises when users try to limit the number of posts and discover that pagination links (like "Next" or "Previous") are missing, preventing visitors from browsing older content.

Why This Happens

Unlike WordPress's native post listing, which automatically handles pagination, the [su_posts] shortcode creates a custom query. By default, this custom query does not include the necessary parameters to generate pagination links. This is why setting posts_per_page="10" will only show the 10 most recent posts with no way to navigate to the next page.

How to Add Pagination to the [su_posts] Shortcode

Based on community findings, there are a couple of approaches to solving this.

1. The Custom Code Solution (For Developers)

A user successfully modified the plugin's core file to add pagination support. This involves editing the file includes/shortcodes/posts.php to add the paged parameter to the query arguments and then output pagination links.

Warning: Modifying plugin files directly is not recommended, as your changes will be overwritten the next time the plugin updates. This method is shown for educational purposes and to illustrate how the shortcode works.

// Example of the modification made (around line 250 in posts.php)
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$args = array(
  'posts_per_page' => $posts_per_page,
  'paged'          => $paged, // This parameter was added
  // ... other args
);

// Later, pagination functions like get_next_posts_link() are used to output the links.

2. The Recommended Solution: Custom Template

The most sustainable and upgrade-safe method is to create a custom template for the posts shortcode. This allows you to fully control the output, including pagination, without touching the plugin's core files.

Here’s how to do it:

  1. In your active theme's directory, create a folder named templates if it doesn't already exist.
  2. Copy the default template file from the plugin: /wp-content/plugins/shortcodes-ultimate/templates/default-loop.php
  3. Paste it into your theme's new templates folder: /wp-content/themes/your-theme/templates/
  4. Rename the file (e.g., custom-pagination-loop.php).
  5. Open this new file and add the necessary code to output pagination links. You can use standard WordPress pagination functions like the_posts_pagination(), next_posts_link(), and previous_posts_link() after the end of the while loop.
  6. In your shortcode, specify your new custom template: [su_posts template="templates/custom-pagination-loop.php" posts_per_page="10"]

By using a custom template, you future-proof your site against plugin updates and gain complete control over the design and functionality of your post lists.

Conclusion

While the [su_posts] shortcode doesn't include built-in pagination, the plugin's architecture supports adding it through custom templates. This method is the recommended best practice for solving the pagination issue and enhancing the shortcode's output to meet your specific needs.

Related Support Threads Support