How to Use Shortcodes to Display Multisite Posts

You can find a lot of examples on the plugin page how you can get and display network posts. But sometimes you may need to display those posts directly on a page created with a builder, for example some kind of Beaver Builder or Elementor.

In this case, if creating a custom page template for that is not your thing, you can try shortcodes.

Shortcodes – is a basic WordPress functionality that allows to run any custom code just in the content of your posts and pages. You can find out a little bit more about shortcodes in official WordPress documentation and also another article. But for now let’s begin with a simple example and break it down into two steps.

1. Create a Shortcode

The simplest shortcode you could ever image may look like this:

add_shortcode( 'misha_test_shortcode', function() {
	
	return date( 'Y' ); // it will display the current year dynamically
	
} );

But we we are talking about using examples for my plugin, it for sure may look a little bit more complex. But the idea is the same:

add_shortcode( 'SHORTCODE NAME', function() {
	
	// here goes the code
	
} );

If you have no idea where to insert these code snippets, check this guide.

2. Display Shortcode in your Posts

Once the shortcode is ready, we have to use it! Usually you need just to insert [SHORTCODE NAME] into your post content. But for some builders the process might be slightly different.

In case you’re using Elementor, for example, you will need its “Shortcode” widget.

shortcode widget in Elementor

And then:

Using shortcodes in Elementor

Need more help?