Warning: Trying to access array offset on false in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 216
remove_shortcode() - 删除短代码的钩子 - WordPress函数 - WordPress动力
当前浏览:首页 / WordPress函数 / remove_shortcode()

remove_shortcode( string $tag )

删除短代码的钩子


Warning: Undefined array key -1 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 185

Warning: Undefined array key 2 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 186

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "e3bd376c8a325cae20208df4f7e3936e" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "bd90c72f298c8a73bfc1a4a3c580d3e9" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

removemore...

shortcode 短码


参数

$tag

(string)(必填) 短代码标签,用于移除钩子。


Warning: Undefined variable $o in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference.php on line 92

源码

查看源码 官方文档


更新日志

版本描述
2.5.0开始引入

使用示例

  • 示例1
    //添加自定义 shortcode 
    add_action( 'init', 'my_add_shortcodes' );
    function my_add_shortcodes() {
    	add_shortcode( 'myShortcode', 'my_shortcode_function' );
    }
    //移除
    add_action( 'init', 'remove_my_shortcodes',20 );
    function remove_my_shortcodes() {
    	remove_shortcode( 'myShortcode' );
    }
    
  • 示例2
    /**
     * Remove shortcodes if we are on some specific page
     */
    function prefix_remove_shortcode_trigger_on_specific_pages() {
    
    	// page ids where we want to remove shortcodes
    	$page_ids = array( 22, 2599 );
    
    	// array of shortcode tags to be removed.
    	$shortcodes_to_remove = array( 'my_shortcode_1', 'someone_other_shortcode' );
    
    
    	if ( in_array( get_the_ID(), $page_ids ) ) {
    
    		foreach ( $shortcodes_to_remove as $shortcode_tag ) {
    			remove_shortcode( $shortcode_tag );
    		}
    	}
    
    }
    
    add_action( 'the_post', 'prefix_remove_shortcode_trigger_on_specific_pages', 20 );