• Hi

    I am trying to make a shortcode that I can add insert this: <?php echo sharing_display(); ?>.

    I tried an obstart function.

    function ShareShortcode() {
    ob_start('<?php echo sharing_display(); ?');
    }
    add_shortcode('jpshare', 'ShareShortcode');

    I may be on the complete wrong track.

    Can you please give me the code.

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • That’s close but you need to get the contents and then close it as well. Just opening it doesn’t do anything the right way.

    function my_function () {
        ob_start ();
    
        // Your output goes in here.
    
        $html = ob_get_contents ();
        ob_end_clean ();
    
        return $html;
    }
    Thread Starter Matthew

    (@kidsguide)

    When I go like this, the shortcode doesn’t work.

    function my_function () {
        ob_start ();
    
        function ShareShortcode() {
    ob_start('<?php echo sharing_display(); ?');
    }
    add_shortcode('jpshare', 'ShareShortcode');
    
        $html = ob_get_contents ();
        ob_end_clean ();
    
        return $html;
    }

    Am I doing this right?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Obstart Shortcode’ is closed to new replies.