Monarch social share shortcode

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 the following new line below it:

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

Add this new display_inline_share_shortcode() function above it:

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.

Need Help?

Use the comment form to ask for help and share ideas or pay me $38.95 to do this for you. I can be hired through WP Service Masters.

Win the battle. Social Warfare Dynamik Website Builder Author Pro

Leave a Reply

19 Comments on "How to Add a Social Sharing Shortcode to Monarch from Elegant Themes"

Notify of
Sort by:   newest | oldest | most voted

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

[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.

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 it's hooks
$monarch = $GLOBALS['et_monarch'];

// Remove default display
remove_filter( 'the_content', array( $monarch, 'display_inline' ) );

// Display in custom place instead
add_filter( 'social_share_content', array( $monarch, 'display_inline' ) );
} );

Now you just need to setup Monarch and enable inline buttons.

And DONE, buttons are displayed in your custom place :)

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?

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?

wpDiscuz

Free to your inbox

Join our mailing list to receive the latest news and updates from JournalXtra.

You have Successfully Subscribed!