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:
- In your active theme's directory, create a folder named
templatesif it doesn't already exist. - Copy the default template file from the plugin:
/wp-content/plugins/shortcodes-ultimate/templates/default-loop.php - Paste it into your theme's new templates folder:
/wp-content/themes/your-theme/templates/ - Rename the file (e.g.,
custom-pagination-loop.php). - 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(), andprevious_posts_link()after the end of thewhileloop. - 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
-
Missing paragraph tag after shortcodehttps://wordpress.org/support/topic/missing-paragraph-tag-after-shortcode/
-
Post data omission from docshttps://wordpress.org/support/topic/post-data-omission-from-docs/
-
Remove date and comment tag in postshttps://wordpress.org/support/topic/remove-date-and-comment-tag-in-posts/
-
Remove “posted” text in posts listhttps://wordpress.org/support/topic/remove-posted-text-in-posts-list/
-
Pagination Alterationhttps://wordpress.org/support/topic/pagination-alteration/
-
WordPress PHP ECHO breaks the_content() – blank, empty displayedhttps://wordpress.org/support/topic/wordpress-php-echo-breaks-the_content-blank-empty-displayed/
-
Remove empty paragraph tagshttps://wordpress.org/support/topic/remove-empty-paragraph-tags/
-
Feature Request: Custom class for posts shortcodehttps://wordpress.org/support/topic/feature-request-custom-class-for-posts-shortcode/
-
Changing the Date Format for multilingual Siteshttps://wordpress.org/support/topic/changing-the-date-format-for-multilingual-sites/
-
Problem with custom shortcode add-on (PHP-code)https://wordpress.org/support/topic/problem-with-custom-shortcode-add-on-php-code/
-
Replace tag withhttps://wordpress.org/support/topic/replace-tag-with/
-
ShortCodes Ultimate su_post youtube – phphttps://wordpress.org/support/topic/shortcodes-ultimate-su_post-youtube-php/
-
Notice: Trying to get property ‘ID’ of non-object in /https://wordpress.org/support/topic/notice-trying-to-get-property-id-of-non-object-in-2/
-
Content is disappearinghttps://wordpress.org/support/topic/content-is-disappearing/
-
the_ID() inside shortcodehttps://wordpress.org/support/topic/the_id-inside-shortcode/
-
Su post “the content” isn’t following the posts formathttps://wordpress.org/support/topic/su-post-the-content-isnt-following-the-posts-format/
-
Change H2 of postshttps://wordpress.org/support/topic/change-h2-of-posts/
-
Typo in addons.phphttps://wordpress.org/support/topic/typo-in-addons-php/
-
su_pullquote not honoring class=https://wordpress.org/support/topic/su_pullquote-not-honoring-class/
-
Plugin is not loaded on custom post type archive pagehttps://wordpress.org/support/topic/plugin-is-not-loaded-on-custom-post-type-archive-page/
-
posts shortcode prevents page from paginatinghttps://wordpress.org/support/topic/posts-shortcode-prevents-page-from-paginating/
-
The plugin automatically removes the taghttps://wordpress.org/support/topic/the-plugin-automatically-removes-the-tag/
-
Can we use PHP code?https://wordpress.org/support/topic/can-we-use-php-code/
-
Text inserted in shortcodehttps://wordpress.org/support/topic/text-inserted-in-shortcode/
-
Changing Date Formathttps://wordpress.org/support/topic/changing-date-format-12/
-
New Line/Empty line isn’t workinghttps://wordpress.org/support/topic/new-line-empty-line-isnt-working/