Programmatically add widgets to sidebars

When I started this answer it should be just a small note. Well, I failed. Sorry! Stay with me, there is a goody hidden deep down … How WordPress widgets are stored The list of widget is stored in an option named ‘sidebars_widgets’. A var_export() may give something like the following: array ( ‘wp_inactive_widgets’ => … Read more

How to create a dashboard widget for one user

You have to wait for wp_loaded to use get_current_user_id(). Example: add_action( ‘wp_loaded’, ‘wpse_80061_load_dashboard_widget’ ); function wpse_80061_load_dashboard_widget() { if ( 1 === get_current_user_id() ) add_action( ‘wp_dashboard_setup’, ‘wpse_80061_add_dashboard_widget’ ); // your function: // add_action( ‘wp_dashboard_setup’, ‘my_catdb_setup’ ); } function wpse_80061_add_dashboard_widget() { wp_add_dashboard_widget( ‘wpse_80061_widget’, ‘Hey!’, ‘wpse_80061_render_dashboard_widget’ ); } function wpse_80061_render_dashboard_widget() { echo ‘hey!’; } For a dashboard widget … Read more

remove post and categories/tags count from right now dashboard widget

There is no filter in PHP, so we have to use JavaScript: add_action( ‘admin_footer-index.php’, ‘wpse_82132_hide_rows’ ); function wpse_82132_hide_rows() { $rows = array ( # ‘posts’, # ‘pages’, ‘cats’, // meoww! ‘tags’, # ‘comments’, # ‘b_approved’, # ‘b-waiting’, # ‘b-spam’, ); $find = ‘.’ . join( ‘,.’, $rows ); ?> <script> jQuery( function( $ ) { … Read more

How to create a ‘single’ category widget for woocommerce plugin [closed]

A bit late but perhaps this might still help someone… If you don’t mind hardcoding the parent category name, slug and ID (e.g. “All”, “designer”,”38″) this works for creating a dropdown to jump to child categories of the specified ID: <?php $terms = get_terms( ‘product_cat’, ‘child_of=38’ ); if ( $terms ) { print( ‘<select name=”product_cat” … Read more

Programmatically add widgets to sidebars

When I started this answer it should be just a small note. Well, I failed. Sorry! Stay with me, there is a goody hidden deep down … How WordPress widgets are stored The list of widget is stored in an option named ‘sidebars_widgets’. A var_export() may give something like the following: array ( ‘wp_inactive_widgets’ => … Read more

How to add custom widget above admin_footer

As far as I know you have 2 options. Using admin_footer or load-edit.php and position with absolute or fixed, or use JavaScript. If you creating a completely new posts screen (not a default posts, pages, etc), you can extend WP_List_Table class, specifically the extra_tablenav function. For example: class My_Custom_Table extends WP_List_Table { function extra_tablenav( $which … Read more

RSS dashboard widget not showing visuals

I couldn’t manage to make wp_widget_rss_output to show the content without stripping HTML tags. Reference Q&A’s: WordPress SimplePie modifications Displaying images from external RSS feeds? But, using the function fetch_feed we can grab the full feed contents. Check also the SimplePie function reference. See comments for details: <?php /** * Plugin Name: RSS Dashboard Widget … Read more

Default widgets assignment – isn’t working

I solved the issue using a fallback with PHP conditionals: in my sidebar.php I coded like the following: <?php if( is_active_sidebar(‘my_sidebar’) ) { ?> <div id=”secondary” class=”widget-area”> <ul class=”xoxo”> <?php dynamic_sidebar(‘my_sidebar’); ?> </ul> </div><!– #secondary .widget-area –> <?php } else { ?> <div id=”secondary” class=”widget-area”> <ul class=”xoxo”> <?php // Default Widget : Archives ?> <li … Read more