Using Echo in ShortCode – Stuck

You can also use output buffering to catch all output you generate. Use it like following:

function fl_aries_co_today_shortcode() {
global $wpdb;
$results = $wpdb->get_results("SELECT horoscope FROM wpaa_scope_co WHERE date = CURDATE() AND sign = 'aries'");
ob_start();
foreach($results as $r) {    
echo "

".$r->horoscope."

"; } $content = ob_get_contents(); ob_end_clean(); return $content; } add_shortcode( 'fl_aries_co_today','fl_aries_co_today_shortcode' );

Leave a Comment