Checking post content for a shortcode, but content is being returned as empty
If the shortcode is at the very beginning strpos
returns 0 which is evaluated as false:
Warning
This function may return Boolean FALSE, but may also return a
non-Boolean value which evaluates to FALSE. Please read the section on
Booleans for more information. Use the === operator for testing the
return value of this function.
So change your code like this:
function plugin_has_shortcode() {
global $post;
if ( strpos( $post->post_content, '[shortcode' ) !== false ) {
return true;
}
return false;
}
Or even shorter:
function plugin_has_shortcode() {
global $post;
return strpos( $post->post_content, '[shortcode' ) !== false;
}