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');
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.