Skip to content

Instantly share code, notes, and snippets.

@indikatordesign
Last active September 9, 2017 09:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save indikatordesign/d07e5fa6a455c03db1b944bec985a98c to your computer and use it in GitHub Desktop.
Save indikatordesign/d07e5fa6a455c03db1b944bec985a98c to your computer and use it in GitHub Desktop.
[Shortcode-Finder]Fork of the shortcode-finder described by wpbeginner.com
<?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