• Resolved MellonCrust

    (@melloncrust)


    Hi,

    I can create an Object in php register it for a shortcode and inset it in a page.

    But i can not figure out how to return data to different places in a paragraph or page.

    This is some test code:

    class ScTest{
        public function __construct()
        {
            add_shortcode('sc1', array($this, 'shortcode'));
    	add_shortcode('sc2', array($this, 'shortcode2'));
    
    	add_filter('widget_text', 'do_shortcode');
        }
    
    // code for sc1
        public function shortcode()
        {
    	echo 'not';
        }
    
    // code for sc2
        public function shortcode2()
        {
    	echo '1/4/2015';
        }
    }
    
    $sct = new ScTest();

    Useable short codes are:

    [sc1]
    [sc2]

    I was thinking that if I created a class I could use methods in paragraphs (via shortcode) to say somthing like this:

    page
    I am a model citizen of planet earth.

    with shortcodes

    I am a [sc1] model citizen of planet earth.

    or:

    I am a [sc1] model citizen of planet earth [sc2].

    but the page output is:

    not1/4/2015
    I am a model citizen of planet earth.

    I want an output like:
    I am a not model citizen of planet earth 1/4/2015.

    So can someone point me in the right direction, so I can figure this out?

    It would seem that when the page is rendered that the shortcodes are executed first then it renders the paragraph.

    Thanks in advanced.
    Joe.

Viewing 3 replies - 1 through 3 (of 3 total)
  • I think the form is:

    return 'not';

    not

    echo 'not';

    or with longer text, I use:

    $html = 'first bit';
    $html .= 'next bit';
    $html .= 'last bit';
    return $html;

    Thread Starter MellonCrust

    (@melloncrust)

    Hi Lorro,

    That worked! Thanks so much. I’ve spent so much time trying to figure this out… and one swift kick from you set me right.

    Thread Starter MellonCrust

    (@melloncrust)

    lorro, Solved this.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Objects shortcode inserting anywhere in page – help please.’ is closed to new replies.