WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] add_shortcode in functions.php output in wrong order (3 posts)

  1. mmtomm
    Member
    Posted 2 years ago #

    Hi,

    I'm using add_shortcode in the functions.php and when I use it in a page it does output in the wrong order.

    Background.
    I'm using the below function in functions.php where I read a seperate php file which only contains some html. I do this, because the content of this snippet of html does change periodically and is used in different places also outside of WP and I want to change it only in one place.

    function laden_offen_snippet() {
    	$laden_offen = file_get_contents('offen.php', false);
    	echo $laden_offen;
    }
    add_shortcode('offen', 'laden_offen_snippet');

    In the WP page where I use it there is something like this:

    <h1>Title</h1>
    [offen]
    <p>some paragraph</p>

    but the problem is that the part of [offen] appears before the Title in the output.
    May do I wrong when I use echo in the function above?
    Or any other idea, how to get on the right place?
    Thanks a lot
    Tom

  2. alchymyth
    Forum Moderator
    Posted 2 years ago #

    do not use echo in shortcodes - use return instead;

    example:

    return $laden_offen;
  3. mmtomm
    Member
    Posted 2 years ago #

    Wonderful, thank you very much!
    Tom

Topic Closed

This topic has been closed to new replies.

About this Topic