/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.’]’

How to add css classes to widgets using functions.php?

Alright, so I managed to pull it off thanks to @toscho who provided me with this link: Add class to before_widget for all widgets with a dropdown and a counter I kind of worked up through it. All I wanted to do was add one class “col-sm-4” from Bootstrap to the search widget. is_admin() || … Read more

Ask user permission when activating a plugin

Try the following code: add_action( ‘admin_head’, ‘ask_for_activation’ ); function ask_for_activation() { ?> <script type=”text/javascript”> jQuery(function($){ $(‘span.activate a’).click(function(e){ var c = confirm(‘Are you sure wnat to activate?’) if(!c) { e.preventDefault(); return false; } return true; }); }); </script> <?php } You can add those codes in your functions.php in the theme, if you think your theme … Read more

How to target the default Recent Posts and Recent Comments widgets with pre_get_posts?

pre_get_posts is executed before each and every query. Your $query->is_main_query() is making this code change the query only for the Main query. So, if you’re in an archive page, you’re modifying only the archive posts, and not any of the others queries (widgets, menus, etc). But be aware, that code you added there will change … Read more

Create More Widget Holders Like Active Widgets and Inactive Widgets

Probably isn’t considered “best practices” but it gets the job done. Here’s what I did: In my wp-admin/widgets.php, After these lines, // register the inactive_widgets area as sidebar register_sidebar(array( ‘name’ => __(‘Inactive Widgets’), ‘id’ => ‘wp_inactive_widgets’, ‘class’ => ‘inactive-sidebar’, ‘description’ => __( ‘Drag widgets here to remove them from the sidebar but keep their settings.’ … Read more