UPDATE
Seems like the shortcode you're trying to use is not well coded. If they use it somewhere in the templates alone like echo do_shortcode('[share]');
it doesn't really matter since the '[share]'
is the only content passed to do_shortcode()
. In your case you're trying to reuse the shortcode in a context where it's placed among other content - that's what the shortcodes are for in the first place. Try for following code:
add_action('wp_head', function() {
// bail if shortcode doesn't exists
if ( ! shortcode_exists( 'share' ) ) {
return;
}
remove_shortcode( 'share' ); // remove what is defined before in change_item_social_v2()
add_shortcode( 'share', function( $args = [], $content = '' ) {
ob_start();
x_portfolio_item_social_v2( $args, $content );
return ob_get_clean();
} );
}, 100 ); // high hook order 100 > 10 (default), ensure this is called after original change_item_social_v2()
By calling ob_start()
before x_portfolio_item_social_v2()
we are simply preventing whatever is output, since that moment, to "display", instead we store it into a buffer which is flushed and its contents returned by ob_get_clean()
, acting like a proper shortcode handler.
ORIGINAL
I don't see a parse issue here but the obvious mistake is echoing in a function that should return. You see your echo do_shortcode(...)
is actually echoing immediately at that time it's run. echo
will output but will not have a return and it will never be where you expect it to be (inside <div class="kalis"></div>
). First try removing echo