Support

Account

Home Forums Front-end Issues How to Use print instead of echo to stop shortcode output going at top? Reply To: How to Use print instead of echo to stop shortcode output going at top?

  • Shortcodes should not echo or output anything. Shortcodes need to return the html that they create.

    
    function rightsidebarf( $atts, $content = null ) {
      $output = '';
      $rows = get_field('caci_side_bar_content', 'option');
      if($rows) {
        foreach($rows as $row) {
          if($row['caci_side_bar_description']) {
            $output = '<a href="'.$row['caci_side_bar_url'].
                      '" alt="'.$row['caci_side_bar_description'].
                      ' '.bloginfo('name').'"><img src="'.
                      $row['caci_side_bar_image'].'" title="'.
                      $row['caci_side_bar_description'].' '.
                      bloginfo('name').'" /></a>';
          } // end if row
        } // end foreach
      } // end if rows
      return $output;
    }
    add_shortcode('rightsidebar', 'rightsidebarf');