WordPress.org

Ready to get started?Download WordPress

Forums

Shortcodes Pro
[resolved] Insert custom code for php goes at top of content (7 posts)

  1. gggt
    Member
    Posted 2 years ago #

    Using "Insert custom code" with PHP, echoed strings always appear at top of editable content no matter where shortcode is placed within the editable page body. (nb return is being called at end in custom code as emphasised in documentation)

    "Insert custom code" with HTML inserts in correct location on page as expected.

    http://wordpress.org/extend/plugins/shortcodes-pro/

  2. Diogo15
    Member
    Posted 2 years ago #

    I think it is your fault(or your theme), cuz you are calling "THE_CONTENT()" before the loop start.. so your "echo" always show up at the start of the loop..

  3. Matt
    Member
    Plugin Author

    Posted 2 years ago #

    Hi gggt,

    You should return the strings too. Consider returning a custom variable with the collection of your output. This is the way to get your code on the right place:

    $out = "Starting my output";
    
    $out .= " Adding another string";
    
    return $out;

    Kind Regards!

  4. theshae
    Member
    Posted 2 years ago #

    I dont understand how to get this working.

    I am using the below code to show some posts.
    query_posts('category_name=breaking-news');

    How do I get the post to show where the shortcode is placed in the content?

    like gggt mine shows at the bottom.

  5. Matt
    Member
    Plugin Author

    Posted 2 years ago #

    Hi Thesahe,

    Same as above, return a custom variable with the collection of your output. Return is a language construct used to exit a function and give a value to the caller of the function[.].
    In this case the shortcode function.

    Kind Regards!

  6. gggt
    Member
    Posted 2 years ago #

    Just for the sake of an explicit FAQ, sksmatt is right (as you'd expect): If output is going to an unexpected place, most likely you're using echo for output instead of collecting all your html into a variable and passing it back at the end with return (see sksmatt's example).

  7. Matt
    Member
    Plugin Author

    Posted 2 years ago #

    Hi gggt,

    Thanks for helping explain it, much appreciated.

    Kind Regards!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic