Shortcode jumps to top (3 posts)

  1. miniCarl
    Posted 6 years ago #

    In editor, I write the following content:

    Lorem ipsum sample text blablabla
    Then some [shortcode at the very bottom]

    However, when i view the page, the generated content from the shortcode is viewed at the top of the page. Note that this is not a css error, since i viewed the source of the generated page and also there is the shortcode stuff at the top.

  2. Michael
    Forum Moderator
    Posted 6 years ago #

    what shortcode?
    all shortcodes?
    self-made short code?

    what is the full code of the shortcode function?


  3. weex
    Posted 5 years ago #

    I experienced this situation myself. This is clearly explained directly on the Codex page for short code functions:


    "The return value of a shortcode handler function is inserted into the post content output in place of the shortcode macro. Remember to use return and not echo - anything that is echoed will be output to the browser, but it won't appear in the correct place on the page."

    So instead of doing echo "stuff"; just return all that you want outputted as a string:

    $string = "stuff";
    return $string;

    But I guess after 3 months of everyone failing to point out this simple fact you may have figured it out on your own already :P

Topic Closed

This topic has been closed to new replies.

About this Topic