Created
August 30, 2016 15:45
-
-
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"]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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