I want to use this as a shortcode to show in any post/page
<?php
$user_id = get_current_user_id();
if ($user_id == 0) {
echo 'You are currently not logged in.';
} else {
echo 'You are logged in as user '.$user_id;
}
?>
when I do this
// Add Shortcode
function uniqueID_shortcode() {
$user_id = get_current_user_id();
if ($user_id == 0) {
echo 'You are currently not logged in.';
} else {
echo 'You are logged in as user '.$user_id;
}
}
add_shortcode( 'naveen', 'uniqueID_shortcode' );
Gutenberg through an error of Updating failed, how to solve this? Thank you in advance.
I want to use this as a shortcode to show in any post/page
<?php
$user_id = get_current_user_id();
if ($user_id == 0) {
echo 'You are currently not logged in.';
} else {
echo 'You are logged in as user '.$user_id;
}
?>
when I do this
// Add Shortcode
function uniqueID_shortcode() {
$user_id = get_current_user_id();
if ($user_id == 0) {
echo 'You are currently not logged in.';
} else {
echo 'You are logged in as user '.$user_id;
}
}
add_shortcode( 'naveen', 'uniqueID_shortcode' );
Gutenberg through an error of Updating failed, how to solve this? Thank you in advance.
Share Improve this question edited May 4, 2019 at 1:16 fuxia♦ 107k39 gold badges255 silver badges459 bronze badges asked May 3, 2019 at 18:28 naveenkharwarnaveenkharwar 234 bronze badges1 Answer
Reset to default 1From add_shortcode
...Note that the function called by the shortcode should never produce output of any kind. Shortcode functions should return the text that is to be used to replace the shortcode. Producing the output directly will lead to unexpected results...
Try changing the echo
s in your callback to return
s and see, if that helps.