wordpress维护

如何清除多余的短代码shortcode

日期:2016-02-22 阅读:1446

dmandwp系统 - wordpress系统和DM系统区块建站>>

http://www.wpbeginner.com/wp-tutorials/how-to-find-and-remove-unused-shortcodes-from-wordpress-posts/

首先我们通过程序来检查有哪些短代码,
然后找到你不要的,再清除它。
在function.php加上下面代码:
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'); 
-------
To use this, you need to create a new WordPress post or page and paste this shortcode inside it:
为了调用它,我们要建一个页面,加上下面代码:
[shortcodefinder find='myshortcode']
------------
这样就找到了短代码,把不要的清除,加上:
add_shortcode( 'shortcodetag', '__return_false' );

这样就好了。

 

<<点击返回