How to Add a Social Sharing Shortcode to Monarch from Elegant Themes

Monarch from Elegant Themes is one of my favourite WordPress social media plugins. It can automatically display social buttons above or below content, in widget areas, in pop-ups, in flyins and in a floating bar. For such a well rounded plugin Monarch lacks one important feature: a shortcode to use to manually add social share buttons within specific pages only.

Fortunately there is something we can do about that…

How to add a new social sharing shortcode to Monarch

We need to make a couple of quick and simple changes to the Monarch plugin code.

These changes to the code will add a new social sharing shortcode to Monarch. The shortcode can be used to manually add inline social share buttons to any specific page, post or widget.

The new shortcode will be [et_social_share].

All edits are made to the plugin file monarch.php.

You will find this file in wp-content/plugins/monarch/monarch.php.

The line numbers mentioned below are accurate for Monarch version 1.3.2. The line numbers may be different for other versions of the plugin.

Use your browser’s find feature (press Ctrl+F) to locate the places where new code is to be added.

The code edits

Use an FTP program or cPanel file browser to locate the file monarch.php. You can also get to this file from the WordPress dashboard by going to the ‘Plugins’ screen to click the ‘edit’ link printed below ‘Monarch Plugin’.

Find line 122. The line begins with the WordPress action hook add_shortcode(). It looks like this:

add_shortcode( 'et_social_share_media', array( $this, 'et_social_share_media' ) );

Add the following new line below it:

add_shortcode( 'et_social_share', array( $this, 'display_inline_share_shortcode' ) );

Find the function display_inline() at around line 4189. It looks like this:

function display_inline( $content ) {
	$monarch_options = $this->monarch_options;

	if ( $this->check_applicability( $monarch_options[ 'sharing_inline_post_types' ], 'inline' ) ) {
		$content = sprintf( '%1$s%2$s%3$s',
			( 'above' == $monarch_options[ 'sharing_inline_icons_location' ] || 'above_below' == $monarch_options[ 'sharing_inline_icons_location' ] )
					? $this->generate_inline_icons( 'et_social_inline_top' )
					: '',
			( 'below' == $monarch_options[ 'sharing_inline_icons_location' ] || 'above_below' == $monarch_options[ 'sharing_inline_icons_location' ] )
					? $this->generate_inline_icons( 'et_social_inline_bottom' )
					: ''

Add this new display_inline_share_shortcode() function above it:

function display_inline_share_shortcode() {
	$monarch_options = $this->monarch_options;
	return $this->generate_inline_icons( 'et_social_inline_top' );

Save the file.

Configure the Monarch plugin

The social share buttons shown by the shortcode will use whatever configs are set under Tools > Monarch > Social Sharing > Inline.

The only difference between the inline buttons and the shortcode buttons is that the shortcode will ignore the setting that determines which post types the inline buttons display on. The shortcode share buttons will display on any page or post whether Monarch’s inline share buttons are enabled for pages, posts or neither.

Use the shortcode

The shortcode is [et_social_share]. Use it in any page or post. Put it wherever you want Monarch social share buttons to show.

Take note that…

The code edits will be overwritten when Monarch is updated to a new version. Hopefully Elegant Themes will add a shortcode for social sharing buttons in a future release. Until Elegant Themes adds the shortcode feature to the plugin you will need to add the code whenever the plugin is upgraded.

How to center Monarch social share buttons

The buttons can be centered with the following CSS.

Put the CSS in the Custom CSS box in Monarch’s general settings. The box is at the bottom of the page Tools > Monarch > General Settings. This will also affect automatically added inline social share buttons.

.et_social_networks {
	text-align: center!important;
.et_social_icons_container li {
	display: inline-block!important;

Want a Better Social Sharing Plugin?

We moved away from Monarch some time ago. We now use Social Pug, which includes click to tweet in the Pro version. It is reasonably priced and comes with a migration tool that restores social share counts captured by other plugins.

Need Help?

Use the comment form to ask for help and share ideas or pay WP Service Masters to do this for you. Licensed installers of Social Pug Pro.

Sharing is caring!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

newest oldest most voted
Notify of

Can you provide a solution for the floating sidebar, as opposed to inline buttons?

Hi There! Thanks a lot for this! I have a problem and it is than the shortcode don’t dissapier when i put it, i mean, it shows the buttons and the writteng shortcode above it. What can i do?


This is what I was looking for, but unfortunately it doesn’t work.. Do you know what could be the problem?


Almost perfect… but I was looking for sharing buttons inside pages built with Divi Builder, in a specific column after a specific content and this code put sharing buttons above content (that’s what is set for posts). Thanks anyway for that sharing which works very well.

If you want the shortcode to display inline icons where you put it, you must change the class inside the function you add.

In the last line (the return line of the function) replace ‘et_social_inline_top’ with anything else (for instance i use ‘et_social_inline_custom’


Beautiful. Finally I can actually use Monarch :D

Sherwin Ramnarine

[Insert Street Fighter II voice saying “PERFECT”] :D


Hi, is there a way to add a php snippet inside a template file to display share buttons?


Actually, I tried this and it works:

Thanks for your article!


Hi, thanks for a fantastic article. I have the icons showing and they are working ok. However they are very spread out as though there is the invisible name of each social media icon between them. Please could you tell me how to group them together next to each other to the left of the post. Many thanks


Hi Lee.
Thank you for your article! Works perfect.
May I ask, how you manage to get the ‘share-with-email’ function (the light blue square to the right)..?
It’s not part of the Monarch version 1.3.5.
Best regards.

Filipe (Portugal)

Thanks, just perfect solution for my problem!

Hello Lee,

Great post, thanks! Do you know how to do the in media share buttons on pages? That’s was I was really looking for and arrive here.
Thank you very much for your help!


Hi there, I have a solution how to display inline buttons wherever you want, without editing plugin files. First, you need to create hook (filter) somewhere in your theme, e.g. if you want to display those buttons in sidebar, add something like this to the top of sidebar.php: echo apply_filters( 'custom_share_buttons', ''); Then remove default inline buttons display (before/after content) and instead display those buttons in your custom place (e.g. sidebar). So add this to functions.php: add_action( 'init', function() { if ( ! isset( $GLOBALS['et_monarch'] ) ) { return; } // Get Monarch global object, so we can work with… Read more »

Thank you so much, this works perfectly!

It’s much better not to edit the plugin code where possible, and there’s a much simpler solution.
Use the following code in your shortcode and then save whichever inline settings you want on the Monarch settings page.

$monarch = $GLOBALS['et_monarch'];
return $monarch -> generate_inline_icons( 'your-class-name' );


Instead for the sidebar?

function monarchShortcode(){
$monarch = $GLOBALS[‘et_monarch’];
$monarch_options = $monarch->monarch_options;
return $monarch->generate_inline_icons(‘et_social_inline_top’);

add_shortcode(‘social_share’, ‘monarchShortcode’);

add this code in functions.php and put this shortcode [social_share] where you want


Emiliano and Shahar, thank you for sharing! This works really well as completed by Emiliano. I had to change the quotes though, which are ‘curved’ and not real quotes.


This works well but still puts the icons at the top of the screen (based on the ‘et_social_inline_top’). Is there a way we can disable that functionality so that the social buttons appear in a custom position on the page (where the [social_share] shortcode is added to the page template)? Thanks in advance!


I added a class attribute to the shortcode so that you can target it into any class you want.

Usage: [shortcode class=”my_class”]

function monarchShortcode($atts=[], $content = null, $tag = ''){
$atts = array_change_key_case((array)$atts, CASE_LOWER);
// override default attributes with user attributes
$sc_atts = shortcode_atts([
'class' => 'et_social_inline_top',
], $atts, $tag);

$monarch = $GLOBALS['et_monarch'];
$monarch_options = $monarch->monarch_options;
return $monarch->generate_inline_icons($sc_atts['class']);

add_shortcode('social_share', 'monarchShortcode');


hmmm, it only works if I have activate the visual builder. If not the share buttons are again at the top and I dont know why? Has anyone a idea?

Thank you for this tutorial, it was a big help for me :-)

Hi.Thanks for your grate Plugin.I want to add The social called telegram to my network but it’s not available! Please let me know if there is any way to add.
Kind regard


All theses changes on the file “monarch.php” will be kept when I’ll update the plugin later?


Hi, thanks for this aweasome guide!
I’m using this plugin
For some reason share button appears not in place where i put a shortcode, but at the bottom of page.
Idk why, can you help me?

Justin Waggle

Check out my patch. I had the same problem. You have to change the class included in the shortcode.


This patch did not work for me. Instead I found this works:

Replace the class ‘et_social_inline_bottom’ with ‘et_social_inline’. It is found two times in Matt Mirus’s custom code (line 23 and line 27).


This fork recognizes the same patch I discovered.

Thomas Baregren

There is a much easier way. Add following code to your functions.php file:

add_shortcode( 'et_social_share', function() {
global $et_monarch;
return $et_monarch->generate_inline_icons();
} );


Thanks for this, but where i can put this code please ?
And i use this shortcode [monarch_share] where i want


is there any way to use monarch like ‘click to tweet’ plugin. I want to allow users to just share a specific sentence on Twitter.





is there any way to use monarch like ‘click to tweet’ plugin. I want to allow users to just share a specific sentence on Twitter.

I found your article after doing a Google search to find a way to center my inline Monarch social media icons which stupidly default to left alignment, rather than centered. Your code works great thank you. I expect that there have been a lot of updates since you wrote your piece, but you really don’t need to mess PHP and do shortcodes now to use Monarch selectively on some pages or posts and not others I am using WordPress 5.2.1 with Monarch plugin 1.4.12 with latest Divi. From Dashboard -> Pages if I hover over a page built with Divi… Read more »


Thank you. Great tutorial, you made my day!