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

How to modify an image block in Gutenberg WordPress 5?

After some digging and trial/error I have came up with a couple solutions. I was looking for a “Gutenberg” solution so I could avoid using str_replace. First, we need to enqueue our JS and include the wp.blocks package // Add to functions.php function gutenberg_enqueue() { wp_enqueue_script( ‘myguten-script’, // get_template_directory_uri() . ‘/js/gutenberg.js’, // For Parent Themes … Read more

How to remove “prev, next, shortlink” from wp_head()?

One shouldn’t remove them. They are important for search engines like Google. One can remove them like this: remove_action(‘wp_head’, ‘wp_shortlink_wp_head’); remove_action(‘wp_head’, ‘adjacent_posts_rel_link_wp_head’); Here are some additional explanations why they should not be removed and how this effects search engines: Core Code insertion The related trac ticket Google Webmaster Central Article about changes & impact on … Read more

Change admin bar to default:off

add_action(“user_register”, “set_user_admin_bar_false_by_default”, 10, 1); function set_user_admin_bar_false_by_default($user_id) { update_user_meta( $user_id, ‘show_admin_bar_front’, ‘false’ ); update_user_meta( $user_id, ‘show_admin_bar_admin’, ‘false’ ); } Place in theme functions file or you can make into a plugin. Once user registers it will go and set the users admin bar prefs to false. The user can then, once logged in, set this to … Read more