Add post shortcodes to WordPress pages

Displaying Recent Posts in WordPress Using Shortcode

Adding recent posts to a WordPress sidebar is fairly easy, but what if you wanted to show recent posts inside a WordPress post or page? The easiest way to display recent posts in WordPress posts and pages is by using shortcodes.

You’d begin by installing and activating the Display Posts Shortcode plugin. It works out of the box and there are no settings you need to configure.

Simply edit a post or page where you want to display your recent posts. Next, use the shortcode [display-posts] with your own parameters inside the post. The plugin offers a whole range of parameters that you can use with the shortcode. Here are some examples:

Display 5 recent posts with thumbnails and excerpt

1 [display-posts posts_per_page="5" image_size="thumbnail" include_excerpt="true"]

Display recent pages instead of posts

1 [display-posts posts_per_page="5" post_type="page"]

Change the order to title instead of date.

1 [display-posts posts_per_page="5" orderby="title"]

Display recent pages under a specific parent page.

1 [display-posts posts_per_page="5" post_type="page" post_parent="5"]

For a full list of parameters visit the plugin’s documentation.

You can also use these shortcodes inside a text widget, but first you will need to enable shortcodes in your text widgets by adding this code to your theme’s functions.php file or a site specific plugin.

1 add_filter('widget_text', 'do_shortcode');


Watch the video about displaying recent posts on pages and posts inWordpress: