Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save netdesignr/88bb1af13ba5805377cdaed0ae0c091f to your computer and use it in GitHub Desktop.
Save netdesignr/88bb1af13ba5805377cdaed0ae0c091f to your computer and use it in GitHub Desktop.
Check if short-code exists in page and echo something inside Wordpress dashboard
/**
* Check if shortcode exists in page and echo something in Wordpress dashboard
*/
function check_if_shortcode_exists_in_page_and_echo_something()
{
global $post;
if (function_exists('get_current_screen')
&& function_exists('has_shortcode')
&& function_exists('is_admin')
) {
$screen = get_current_screen();
if (isset($screen)) {
if (is_admin() && ($screen->id == 'page') && has_shortcode($post->post_content, 'shortcode-name')) {
echo "Do somethig"
}
if (is_admin()) {
echo "Something else"
}
}
}
}
/**
* The hook
*/
add_action('admin_notices', 'check_if_shortcode_exists_in_page_and_echo_something');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment