admin管理员组

文章数量:1406063

I am trying to debug a shortcode. I have written the following function and placed in my theme's functions.php file:

function michael_function_shortcode() {
    return 'This is the return';
}

I have defined the shortcode as follows:

add_shortcode(‘michael’, ‘michael_function_shortcode’);

And I have included the shortcode on a page:

[michael]

I know the function is there because if I introduce errors I get messages because of debug=true, but [michael] just displays and is not replaced by 'This is the return" as expected.

Where do I go from here? How do I debug this?

I am trying to debug a shortcode. I have written the following function and placed in my theme's functions.php file:

function michael_function_shortcode() {
    return 'This is the return';
}

I have defined the shortcode as follows:

add_shortcode(‘michael’, ‘michael_function_shortcode’);

And I have included the shortcode on a page:

[michael]

I know the function is there because if I introduce errors I get messages because of debug=true, but [michael] just displays and is not replaced by 'This is the return" as expected.

Where do I go from here? How do I debug this?

Share Improve this question edited Jun 29, 2018 at 6:19 fuxia 107k39 gold badges255 silver badges459 bronze badges asked Jun 29, 2018 at 3:35 mkstlwtzmkstlwtz 1411 gold badge1 silver badge5 bronze badges 2
  • 3 Is your actual code using quotes like and , or just '? – Jacob Peattie Commented Jun 29, 2018 at 3:51
  • 1 Jacob - Thank you. The single quotes in add_shortcode were not just ' as they should have been. I corrected them and it works fine. I am just using return. Thank you. – mkstlwtz Commented Jun 29, 2018 at 4:09
Add a comment  | 

1 Answer 1

Reset to default 1

From reading this guide, could you try using a variable to output the return as such?

$output = 'This is the return';
return $output;

Also, if you're calling the shortcode with do_shortcode('[michael]'); in a php file, you'll need to echo this, like so:

<?php echo do_shortcode('[michael]'); ?>

本文标签: shortcodeHow do I debug a short code