unregister_sidebar() - WordPress 函数参考中文文档

返回介绍

unregister_sidebar()

发布于 2017-09-11 字数2179 浏览 1027 评论 0

unregister_sidebar( string|int $sidebar_id )

Removes a sidebar from the list.


描述


参数

$sidebar_id

(string|int)
(Required)
The ID of the sidebar when it was registered.


源代码

File: wp-includes/widgets.php

function unregister_sidebar( $sidebar_id ) {
	global $wp_registered_sidebars;

	unset( $wp_registered_sidebars[ $sidebar_id ] );
}

更新日志

Version 描述
2.2.0 Introduced.

User Contributed Notes

  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note

    Contributed by Codex

    Basic Example

    If added to a child theme’s functions.php file, this will remove the footer sidebars registered by the TwentyTen theme.

    
    function remove_some_widgets(){
    
    	// Unregister some of the TwentyTen sidebars
    	unregister_sidebar( 'first-footer-widget-area' );
    	unregister_sidebar( 'second-footer-widget-area' );
    	unregister_sidebar( 'third-footer-widget-area' );
    	unregister_sidebar( 'fourth-footer-widget-area' );
    }
    add_action( 'widgets_init', 'remove_some_widgets', 11 );
    

    Notes

    In the example, note that we assign a priority of 11 when registering the widgets_init hook. This is because a child theme’s functions.php file is called before the parent theme’s, which means that our call to unregister_sidebar() would accomplish nothing since the sidebar has not yet been registered.

    By lowering the priority of our action, we ensure that it is called after the parent theme’s functions.php file is loaded.

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!