Call dynamic_sidebar but include/exclude named widgets?

dynamic_sidebar() calls wp_get_sidebars_widgets() to get all widgets per sidebar. I think filtering this output is the best way to remove a widget from an sidebar. add_filter( ‘sidebars_widgets’, ‘wpse17681_sidebars_widgets’ ); function wpse17681_sidebars_widgets( $sidebars_widgets ) { if ( is_page() /* Or whatever */ ) { foreach ( $sidebars_widgets as $sidebar_id => &$widgets ) { if ( ‘my_sidebar’ … Read more

Using Bootstrap in themes

A few things to consider: Enqueue stylesheets properly, using wp_enqueue_style(), and hooked into either wp_enqueue_scripts or wp_print_styles Enqueue scripts properly, using wp_enqueue_script(), and hooked into `wp_enqueue_scripts() Ensure that enqueued stylesheets and scripts are only enqueued on the front end, and not in the admin back end. Bootstrap and similar frameworks should only be used on … Read more

Get 10 posts from a WP_Query. If less than 10, get the remainder from elsewhere

You could do something like : $related_posts_query = new WP_Query( $related_posts_args ); if( $related_posts_query->found_posts < 10 ){ $args = array(/* new wp_query args*/); $newquery = new WP_Query( $args ); } # merge the two results $related_posts_query->posts = array_merge( $related_posts_query->posts, $newquery->posts ); $related_posts_query->post_count = count( $related_posts_query->posts ); # do your loop here

WordPress Settings API error

I believe the underlying problem is that the option array keys don’t exist yet. Let’s start here, in your initialization function: if( false == get_option( ‘thanathos_theme_display_options’ ) ) { add_option( ‘thanathos_theme_display_options’ ); } First, this: false == get_option( ‘thanathos_theme_display_options’ ) …should be this: false === get_option( ‘thanathos_theme_display_options’ ) …because you’re expecting an array to be … Read more

How can I set image sizes and still have responsive images using the srcset attribute?

The srcset attribute is constructed from images that are the same aspect ratio. Create a few of those and you’ll be ok. add_image_size( ‘compare-offer-box’, 400, 300, true); add_image_size( ‘compare-offer-box-2’, 800, 600, true); add_image_size( ‘compare-offer-box-3’, 1200, 900, true); for example. The fourth, boolean, argument tells WP to crop to the exact proportions. To resize without cropping, … Read more