Title: Creating a custom shortcode
Last modified: August 21, 2016

---

# Creating a custom shortcode

 *  Resolved [Christopher Glaeser](https://wordpress.org/support/users/cglaeser/)
 * (@cglaeser)
 * [12 years ago](https://wordpress.org/support/topic/creating-a-custom-shortcode/)
 * I prefer to use my own named shortcodes so that I can easily update them in the
   future. I’m using Genesis, and here is the code I wrote:
 *     ```
       function my_share()
       {
           mashsharer();
           return '';
       }
   
       add_shortcode('my-share', 'my_share');
       ```
   
 * Then, I tried adding the following in a post:
 *     ```
       [my-share]
       This is a paragraph.
       [my-share]
       ```
   
 * It almost works, but both sets of Mashshare buttons are at the top of the post.
   I want one to be at the top of the post (before the paragraph) and one to be 
   at the bottom of the post (after the paragraph). Any suggestions on how to implement
   this behavior?
 * Best,
    Christpoher
 * [https://wordpress.org/plugins/mashsharer/](https://wordpress.org/plugins/mashsharer/)

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Rene Hermenau](https://wordpress.org/support/users/renehermi/)
 * (@renehermi)
 * [12 years ago](https://wordpress.org/support/topic/creating-a-custom-shortcode/#post-4989577)
 * Hey Chris,
 * set the display option in the admin panel to “manual” and the shortcode should
   only be visible one time per shortcode.
 *  Thread Starter [Christopher Glaeser](https://wordpress.org/support/users/cglaeser/)
 * (@cglaeser)
 * [12 years ago](https://wordpress.org/support/topic/creating-a-custom-shortcode/#post-4989590)
 * Hi Rene,
 * Thanks for responding but you misunderstood my question. The buttons are not 
   displaying in the proper order with the rest of the article. In the post sample
   above, please note that the shortcode [my-share] is used twice so that the buttons
   appear at the beginning and end of the article. However, both sets of buttons
   appear at the beginning of the article. For some reason, the buttons are out 
   of sequence with the article and always appear before the article. Do you have
   any suggestions on how to serialize the buttons with the output of the article?
 * Best,
    Christopher
 *  [Rene Hermenau](https://wordpress.org/support/users/renehermi/)
 * (@renehermi)
 * [12 years ago](https://wordpress.org/support/topic/creating-a-custom-shortcode/#post-4989610)
 * Hi,
 * your code looks ok so far.
 * Can you try in file mashsharer.php
 * Replace:
 *     ```
       function mashsharer(){
           global $content;
           global $atts;
           $mashsharer = new mashsharer();
           echo $mashsharer->mashsharerShow($atts);
           //$mashsharer->mashsharer_filter_content($content);
       }
       ```
   
 * with:
 *     ```
       function mashsharer(){
           global $content;
           global $atts;
           $mashsharer = new mashsharer();
           return $mashsharer->mashsharerShow($atts);
       }
       ```
   
 * If this work, i will change my shortcode function.
 * _[Moderator Note: Please post code & markup between backticks or use the code
   button. Your posted code may now have been permanently damaged by the forum’s
   parser.]_
 *  Thread Starter [Christopher Glaeser](https://wordpress.org/support/users/cglaeser/)
 * (@cglaeser)
 * [12 years ago](https://wordpress.org/support/topic/creating-a-custom-shortcode/#post-4989628)
 * Rene,
 * Thanks, your proposed change (replace echo with return) worked. I also made a
   slight change to my code as well, which is now:
 *     ```
       function my_share()
       {
           return mashsharer();
       }
   
       add_shortcode('my-share', 'my_share');
       ```
   
 * Now, it will be much easier to convert all the buttons on my site from one plugin
   to another in one simple step. Thanks again.
 * Best,
    Christopher

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Creating a custom shortcode’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/mashsharer_33bbee.svg)
 * [MashShare - Social Media Share Buttons, Social Share Icons](https://wordpress.org/plugins/mashsharer/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/mashsharer/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/mashsharer/)
 * [Active Topics](https://wordpress.org/support/plugin/mashsharer/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/mashsharer/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/mashsharer/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [Christopher Glaeser](https://wordpress.org/support/users/cglaeser/)
 * Last activity: [12 years ago](https://wordpress.org/support/topic/creating-a-custom-shortcode/#post-4989628)
 * Status: resolved