Skip to content

Instantly share code, notes, and snippets.

@hasanm95
Created August 30, 2016 15:45
Show Gist options
  • Save hasanm95/bc981a8c286193d28edfd4116db3100c to your computer and use it in GitHub Desktop.
Save hasanm95/bc981a8c286193d28edfd4116db3100c to your computer and use it in GitHub Desktop.
this shortcode checked that is specific shortcode have in this page or post? . [shortcodefinder find="yourshortcodetag"]
function wpb_find_shortcode($atts, $content=null) {
ob_start();
extract( shortcode_atts( array(
'find' => '',
), $atts ) );
$string = $atts['find'];
$args = array(
's' => $string,
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
echo '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post(); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
<?php
}
echo '</ul>';
} else {
echo "Sorry no posts found";
}
wp_reset_postdata();
return ob_get_clean();
}
add_shortcode('shortcodefinder', 'wpb_find_shortcode');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment