unregister_sidebar() in stand-alone theme not working

Thanks to Milo and G.M. for pointing to the master key, as G.M. said: you have to use a lower priority than one register_sidebar runs, but lower priority means higher number. So the final code that is working: function site_unregister_sidebar() { if ( is_admin() && current_user_can(‘editor’) ) { unregister_sidebar( ‘my_custom_widget_area’ ); } } add_action(‘widgets_init’, ‘site_unregister_sidebar’, … Read more

How can you add a link to a sidebar description?

The sidebar description runs through esc_html(), so you cannot pass HTML directly. But you can use the filter esc_html to insert your desired content. Here is a simple example: add_action( ‘widgets_init’, function() { $desc = “Read the <a href=”http://wordpress.stackexchange.com/q/189749/73″>explanation</a>!”; $placeholder=”PLACEHOLDER”; register_sidebar([ ‘id’ => ‘wpse-189749’, ‘name’ => ‘Link description’, ‘description’ => $placeholder ]); add_action( ‘widgets_admin_page’, function() … Read more

I can’t get my custom widget area to show on my WordPress site

Your have created three sidebars and that are primary_widget_area, secondary_widget_area, footer_widget_area But in the sidebar, you call a different sidebar name sidebar-3; that’s why your sidebars are not displaying. Try the following code in sidebar.php: // To display primary_widget_area sidebar <?php if ( is_active_sidebar( ‘primary_widget_area’ ) ) : ?> <?php dynamic_sidebar( ‘primary_widget_area’ ); ?> <?php … Read more

Add before_content and after_content to register_sidebar

The limitation is down to the existing arguments and how pretty much all widgets typically output content: echo $args[‘before_widget’]; if ( $title ) { echo $args[‘before_title’] . $title . $args[‘after_title’]; } // Widget content echo $args[‘after_widget’]; Some widgets may offer before/after content hooks, but if you want a “global” fix there’s no surefire way around … Read more

Insert Widget option into mark-up with register_sidebar

First you will replace this line <div id=”%1$s” class=”widget %2$s” data-custom-title=””> with <div id=”%1$s” class=”widget %2$s” data-custom-title=”DCT”> Now add the filter in your functions.php file. add_filter( ‘widget_display_callback’, ‘add_custom_data_to_before_widget’, 10, 3 ); function add_custom_data_to_before_widget( $instance, $widget_class, $args ) { if ( ! empty( $instance[‘title’] ) && ! empty( $instance[‘custom-title’] )) { $args[‘before_widget’] = str_replace(‘DCT’, sanitize_text_field ( … Read more