How to unregister a widget from a child theme

Assuming the Parent Theme’s Widget is registered at the widgets_init hook, all you need to do is wrap your unregister_widget() call inside of a function, hook that function into widgets_init, and give your hook a higher priority number than the Parent Theme’s widgets_init-hooked function. Assuming the Parent Theme hooks into widgets_init without giving a priority … Read more

What is the most efficient method for loading widgets in functions.php

Both are acceptable but not recommended. Use locate_template() instead because a child theme can overwrite the loaded file then. Example: $found = locate_template( ‘functions/my-custom-widget.php’, TRUE, TRUE ); The first TRUE tells WordPress not only to search for the file but to load it actually. The second makes it a require_once call. The function return the … Read more

Adding WordPress colorpicker in widget settings

The following worked for me. I using class attribute instead of ID to match multiple color pickers. <script type=”text/javascript”> jQuery(document).ready(function($) { jQuery(‘.color-picker’).on(‘focus’, function(){ var parent = jQuery(this).parent(); jQuery(this).wpColorPicker() parent.find(‘.wp-color-result’).click(); }); }); </script> My Widget form is set up like : <p> <label for=”<?php echo $this->get_field_id( ‘font_color’ ); ?>” style=”display:block;”><?php _e( ‘Font Color:’ ); ?></label> <input … Read more

Displaying Widgets

the_widget() is used to display a specific widget outside of a sidebar. To be honest, this function serves no valuable purpose as you need to hard code the widget $instance parameters, this means that you will need to manually change the code every time you need to change something. So much for dynamica. It would … Read more

/images/image.jpg not working in sidebar

PHP code won’t run inside of a text widget. There are plugins that will let you do that, but this type of thing is strongly discouraged. Add this code to your functions.php file, or better yet, make it a simple little plugin: // Enable the use of shortcodes within widgets. add_filter( ‘widget_text’, ‘do_shortcode’ ); // … Read more

Custom widget using get_categories select menu dropdown

Ok I found a solution thanks to this: Using wp_dropdown_categories in widget options Here is the code I used instead: function form( $instance ) { /* Default Widget Settings */ $defaults = array( ‘title’ => ‘Highlight Category’ ); $instance = wp_parse_args( (array) $instance, $defaults ); ?> <!– Widget Title –> <p> <label for=”<?php echo $this->get_field_id( … Read more

Completely disabling widgets

One option would be to simply flush the widget code out of the sidebar.php file, as well as the header/footer/post pages if they are using widgets. However, take a peek at this code snippet (courtesy of this site), which you can add to your functions.php file and will disable the widgets. I think this would … Read more

Why use widgets?

I battled with this very same question. I’m presently developing my own ability to develop WordPress sites. My employer is launching numerous websites on the engine, and is moving me from general PHP work to focused WordPress development. The thing is, these sites will all be managed by other people, and not myself. Using widgets … Read more

WordPress select dropdown list in widget

See my comment above…you’re using get_field_id() on the name-attribute, where it should be get_field_name(). get_field_id() returns ‘widget-‘.$this->id_base.’-‘.$this->number.’-‘.$field_name, whereas get_field_name() returns ‘widget-‘.$this->id_base.'[‘ . $this->number . ‘][‘ . $field_name.’]’