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?

  • 3
    Is your actual code using quotes like and , or just '? – Jacob Peattie Jun 29 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 Jun 29 at 4:09

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_sortcode('[michael]'); in a php file, you'll need to echo this.

  • The problem was my quotes on the shortcode string. All fixed. – mkstlwtz Jul 2 at 21:19

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.