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

  1. mmtomm
    Posted 4 years ago #


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

    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:

    <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

  2. Michael
    Forum Moderator
    Posted 4 years ago #

    do not use echo in shortcodes - use return instead;


    return $laden_offen;
  3. mmtomm
    Posted 4 years ago #

    Wonderful, thank you very much!

Topic Closed

This topic has been closed to new replies.

About this Topic