I don’t know what “this isn’t working” means but a shortcode should not echo
anything. You should concatenate a string and return
it.
if (is_single()){
$str="";
if($type == 'audio'){
$str .= '<div class="sub-audio"><h6 class="sub_btn">Audio</h6>';
}
if($type == 'video'){
$str .= '<div class="sub-video"><h6 class="sub_btn">Video</h6>';
}
foreach ( $bookmarks as $bookmark ) {
$str .= sprintf(
'<a class="wpb_button_a" href="https://wordpress.stackexchange.com/questions/137787/%s"><span class="wpb_button wpb_%s wpb_default2"><i class="icon-%s"> </i>%s</span></a>',
$bookmark->link_url,
$bookmark->link_name,
$bookmark->link_name,
$bookmark->link_name
);
}
$str .= '</div>';
}
return $str;
I don’t see anything else obviously wrong, though the code you posted is incomplete, so I am guessing that that is the problem.