Last active
September 9, 2017 09:55
-
-
Save indikatordesign/d07e5fa6a455c03db1b944bec985a98c to your computer and use it in GitHub Desktop.
[Shortcode-Finder]Fork of the shortcode-finder described by wpbeginner.com
This file contains hidden or 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
<?php | |
// This is a fork of the shortcode-finder described in this useful post: http://www.wpbeginner.com/wp-tutorials/how-to-find-and-remove-unused-shortcodes-from-wordpress-posts/ | |
// Just add the snippet in your themes functions.php. You can use this shortcode in a post or page, as shown in the following example: | |
// [find_shortcode name='et_pb_dfbm_blog'] | |
add_shortcode( 'find_shortcode', function( $atts, $content = false ) | |
{ | |
$def = [ 'name' => '', ]; | |
$atts = shortcode_atts( $def, $atts ); | |
$args = | |
[ | |
's' => esc_attr( $atts['name'] ), | |
'post_type' => [ 'post', 'page' ], | |
'posts_per_page' => 100, | |
]; | |
ob_start(); | |
$query = new WP_Query( $args ); | |
if ( $query->have_posts() ) | |
{ | |
echo '<ul>'; | |
while ( $query->have_posts() ) | |
{ | |
$query->the_post(); | |
?> | |
<li><a href="<?php the_permalink() ?>" target="_blank"><?php the_title(); ?></a></li> | |
<?php | |
} // end while | |
echo '</ul>'; | |
} // end if | |
else echo 'No posts to delete..'; | |
wp_reset_postdata(); | |
return ob_get_clean(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment