Remove echo from shortcode

‘echo’ statement will not work in shortcode function. shortcode function is just returning the variable; So your code will be like this: if(get_field(‘group’)) { $html=””; $html.= “<ul class=”sponsors”><h2>” , get_the_title() , “</h2>”; while(has_sub_field(‘group’)) { $attachment_id = get_sub_field(‘image’); $size=”sponsorimage”; $image = wp_get_attachment_image_src( $attachment_id, $size , false ); $link = get_sub_field(‘link’); $html.= “<li>”; $html.= “<a href=”” , … Read more

How to Reference/Echo Variable from Another PHP Function

As indicated in the comments, you should return the string, not echo it: add_shortcode(‘yt’, ‘getYoutubeDetails’); function getYoutubeDetails($atts) { extract(shortcode_atts(array( ‘video’ => ” ), $atts)); // Get YouTube data via the API $JSON = file_get_contents(“https://gdata.youtube.com/feeds/api/videos?q=$video&alt=json”); $JSON_Data = json_decode($JSON); $views = $JSON_Data->{‘feed’}->{‘entry’}[0]->{‘yt$statistics’}->{‘viewCount’}; $views = number_format($views); $duration = $JSON_Data->{‘feed’}->{‘entry’}[0]->{‘media$group’}->{‘yt$duration’}->{‘seconds’}; $s = “<iframe width=\”1280\” height=\”720\” src=\”//www.youtube.com/embed/$video?showinfo=0&rel=0&modestbranding=1&theme=light&iv_load_policy=3&autohide=1&enablejsapi=1\” frameborder=\”0\” allowfullscreen></iframe>”; $s … Read more