Add class to before_widget from within a custom widget

Aha, so the $before_widget variable is a string representing div element: <div class=”widget my” id=”my-widget-1″> . So I checked the $before_widget for the “class” sub-string and added my $widget_width value to it. The code is from my custom widget file: function widget( $args, $instance ) { extract( $args ); … //other code $widget_width = !empty($instance[‘widget_width’]) … Read more

Hide specific categories from category widget

I know this post is pretty old, but because I came across the same issue and this post came up higher than one with a solution, I figured I’d add this, which worked for me. Source: http://coffeecupweb.com/how-to-exclude-or-hide-categories-from-category-widget-in-wordpress-sidebar/ //Hide categories from WordPress category widget function exclude_widget_categories($args){ $exclude = “1,4,8,57,80”; $args[“exclude”] = $exclude; return $args; } add_filter(“widget_categories_args”,”exclude_widget_categories”);

How to load Widget javascript + css files only if used?

wp_print_scripts and wp_print_styles hooks are fired way before your widget function so that is way it’s not working. A solution to that would be to include the scripts in the footer using wp_print_footer_scripts hook, take a look at Jan’s answer to a similar question Or a much nicer solution take a look at Sorich’s answer … Read more

Give Editor Access To Sidebar

The edit_theme_options capability should allow the user to edit the sidebar as described on this page : http://codex.wordpress.org/Appearance_Widgets_SubPanel Code to add to functions.php $role = get_role(‘editor’); $role->add_cap(‘edit_theme_options’); Edit: This should work to prevent editor accessing themes or menus function custom_admin_menu() { $user = new WP_User(get_current_user_id()); if (!empty( $user->roles) && is_array($user->roles)) { foreach ($user->roles as $role) … Read more

How Can I Add the “Insert From URL” Tab to a Custom 3.5 Media Uploader?

I’ve been digging through the source code for a similar reason; I’d like to add the “Attachment Display Settings” to the default “select” frame. As far as I can tell, this can’t be done by passing parameters to wp.media(), as we would all like. wp.media currently has the two frames (“post” and “select”), and the … Read more

Loading scripts only if a particular shortcode or widget is present

You can use the function is_active_widget . E.g.: function check_widget() { if( is_active_widget( ”, ”, ‘search’ ) ) { // check if search widget is used wp_enqueue_script(‘my-script’); } } add_action( ‘init’, ‘check_widget’ ); To load the script in the page where the widget is loaded only, you will have to add the is_active_widget() code, in … Read more