Welcome.
-
By using
die
function, You are stopping the process and it will stop immediately after running the shortcode callback. Better to let the rest of the code to be executed. -
You need to return something in shortcode callback function instead of sending headers using
die
orecho
.
So, change your code to something like the following one and it should work. You are free to wrap it in init
hook.
add_shortcode(
'my_shortcode',
function($atts, $content="") {
return 'This is from My shortcode!';
}
);
- The condition for checking shortcode existence is problematic. If you want to check if a certain shortcode exists in a page,
has_shortcode
function. Checkhas_shortcode
document here.