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

Trigger Submit Event when Widget is added to Sidebar

Based off the example @mrwweb provided above and some additional code, here is an answer that works. This answer forces a widget to save when a widget is added to a sidebar. It finds all the “Save” buttons and triggers their click event thus saving the widget. The count variable is used to stop an … Read more

List authors with posts in a category

This can become a quite an expensive operation which can seriously damage page load time. At this stage, your code is quite expensive. Lets look a better way to tackle this issue. What we need to do is to minimize the time spend in db, and to do this, we will only get the info … Read more