• Resolved muchmuch11

    (@muchmuch11)


    I want to call shortcode in the middle of content. I put the shortcode correctly, but why it always appear on top of content? Any way to work around this?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Most times that’s because the shortcode has been programmed incorrectly and outputs it’s content rather than returning it for display.

    Where did the shortcode come from?

    Thread Starter muchmuch11

    (@muchmuch11)

    I create the code myself, trying with most simple code, the result will always appear at top of my content area regardless wherever I put the shortcode caller, on 2nd paragraph, 3rd, or 4th. It seems this behavior is WP default, right? Any solution to have the result placed correctly where I put the caller on content?

    When you programmed the shortcode, how did you do the output?

    Like this:

    echo "<p>My content goes in here.</p>";
    echo "<p>This will display before everything else on the page.</p>";

    Or like this:

    $content = "<p>My content goes in here</p>";
    $content.= "<p>This will display where the shortcode is placed.</p>";
    
    return $content;

    I’ll give you a big tip – The second one is right, and the first one is wrong. With that in mind I’m guessing that you’ve done it the first way. Change that and you’ll have it right.

    The reason for this is that any output from a shortcode is, well – output, before the pages content is created, so if you use standardecho statements in a shortcode it will output your content right at the start of the page no matter where the shortcode is in the content.

    Thread Starter muchmuch11

    (@muchmuch11)

    YOU’RE AWESOME!! yes, I used the first one. Now it’s in intended place. Ok, I understand that now. Thanks a lot!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Shortcode in the middle of content’ is closed to new replies.