How Can I Register Menus and Widgets Conditionally Based on Theme Options/Settings?

Below is the code you need. Your issue could be that you’re not first setting up the variable $display_options to contain your options, or that you not asking if the option is set. add_action(‘widgets_init’, ‘arphabet_widgets_init’); function arphabet_widgets_init() { $options = get_option(‘muffin_options’); if(isset($display_options[‘header_layout’]) && $display_options[‘header_layout’] == ‘1’) { register_widget(‘arphabet_widget_1’); } if(isset($display_options[‘header_layout’]) && $display_options[‘header_layout’] == ‘1’) { … Read more

Display sidebar that created in functions.php

Here’s the way i would code it. Tested Add to functions file add_action( ‘widgets_init’, ‘wpsites_add_widget’ ); function wpsites_add_widget() { register_sidebar(array( ‘name’=>’Sidebar-Aries’, ‘id’ => ‘sidebar-aries’, ‘description’ =>’Display all the contents of sidebar at Aries page.’, ‘before_widget’ => ”, ‘after_widget’ => ”, ‘before_title’ => ”, ‘after_title’ => ”, )); } Or you could use this code in … Read more

Count widgets in position and set class

I found an answer on this very site that didn’t come up before in search before @ Get number of widgets in sidebar function cosmos_bottom_sidebar_params($params) { $sidebar_id = $params[0][‘id’]; if ( $sidebar_id == ‘sidebar-bottom’ ) { $total_widgets = wp_get_sidebars_widgets(); $sidebar_widgets = count($total_widgets[$sidebar_id]); $params[0][‘before_widget’] = str_replace(‘class=”‘, ‘class=”span’ . floor(12 / $sidebar_widgets) . ‘ ‘, $params[0][‘before_widget’]); } … Read more

how to extend a WP_widget twice

You have to make sure that all of your parameters are passed all the way through to the WP_Widget class. Your code is very truncated but I am pretty sure that is what you are doing wrong. The widget code below works– it doesn’t do much of anything, but it works. See if you can … Read more

Widget Area: Modify $param[‘xy’] from widget-$n

The dynamic_sidebar_params filter is called before each widget is displayed, so multiple times in the same sidebar. It filters the $args and $instance parameters that will be passed to the widget. If you only want to execute it for the third widget of a specific sidebar, you should check for the sidebar ID (found in … Read more

How to check if widget has automatic title

Any widgets written to operate as the Core “Recent Posts” widget does can be forced to skip the title by a filter on widget_title: function widget_title_hack_191120($title, $instance) { if (empty($instance[‘title’])) { $title=””; } return $title; } add_filter(‘widget_title’,’widget_title_hack_191120′, 10, 2); I don’t know if there is a generic solution to the problem. Any widget could avoid … Read more

How to add the widgets manually to the sidebar?

Have a look at the the_widget() function. The first argument is required. It is the PHP class name of the widget. For example: <div class=”sidebar”> <?php the_widget(‘WP_Widget_Search’) ?> </div> You can also pass on extra arguments: <div class=”sidebar”> <?php the_widget(‘WP_Widget_Text’, ‘title=Hello&text=World’) ?> </div>

Need help adding additional controls to a custom widget Part 2

Here is an updated version of the widget which handles the vertical layout option, including categories, and excluding categories. Handling the vertical layout option is pretty straightforward; we just check to see if the option is checked, and if so, output the appropriate classes. Handling the inclusion/exclusion of categories is a little more complex because … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)