• Resolved Christopher Glaeser

    (@cglaeser)


    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://ww.wp.xz.cn/plugins/mashsharer/

Viewing 4 replies - 1 through 4 (of 4 total)
  • 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

    (@cglaeser)

    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

    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

    (@cglaeser)

    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.