一个更简洁的解决方案是将所有逻辑和标记封装到短代码本身中:
function conditional_shortcode_wpse_188037() {
global $post;
if ( $post->post_author == get_current_user_id() ) {
$ret = \'<div class="my_edit_button">\';
$ret .= \'other shortcode content\';
$ret .= \'</div>\';
return $ret;
}
}
add_shortcode(\'something\',\'conditional_shortcode_wpse_188037\');