My exact scenario involved almost finishing my work, but heading to bed anyway. That meant I had made some changes that were not fully tested before logging off. The following day I discovered that there was no link appearing where I had placed my shortcode, actually nothing was appearing in that location. The shortcode was either returning an empty value or was not being registered or parsed or something!

Troubleshooting

This isn’t an in-depth tutorial on the various ways of troubleshooting shortcode issues. So all I’m going to say about my troubleshooting is that it included some use of var_dump in the WP core shortcodes.php file to check if my shortcode was being registered or not. It’s a good place to start getting to know how WordPress works.

WordPress TwitchPress Shortcode Broken Fixed

Solution

My solution, which I realized after doing the var_dump’s in shortcode.php file, was an incorrect use of add_filter( ‘wp_content’ ) which was my doing. The dumps told me that my shortcode tag did not exist at the point of do_shortcode() but it was in the array of registered shortcodes. So it was being removed and filters are great at doing that sort of thing.

I’m using the wp_content filter hook to add front-side notices. So I need to prepend some HTML to a posts content value. When using a wp_content filter, we need to ensure we return the original content. I was not doing this because I was performing a null return in my filter function instead of returning the original content.

WordPress filter broke shortcode

 

Advertisements