WordPress Cover Block Less Height on Mobile

I love using the WordPress cover block, but have always found that this block takes up too much height on mobile devices. I solved this problem by adding a class to the cover block that restricts its height and maintains some responsiveness on narrower screens. In my case I have set the class to kick-in at 922 pixels.

Locomotive Alison at Brighton Railway Station.

The photograph above (© South Coast View) shows locomotive Alison at Brighton Railway Station in West Sussex.

How to control height of the cover block on mobile

The screenshot displayed below shows how I added a class called change-height-of-cover-block in the block settings. In the code example below, I added CSS into my child theme, effective when the screen width is 922 pixels wide or less.

Adding a class in the WordPress cover block settings.
Adding a class in the WordPress cover block settings
/* On narrow screens force less height of cover block */

@media only screen and (max-width: 922px) {
.change-height-of-cover-block {
  min-height: 280px !important;
  }

CSS code to control height of the cover block on mobile.

If you are viewing this post on a desktop, you will see a large image of the locomotive above. As you narrow your browser width, the image suddenly reduces in height to 280 pixels. You will probably need to adjust the pixel height in your additional CSS to better suit your image and the values you have added in the cover block settings. On mobile devices, the image retains some top, right, bottom, and left aspects around the locomotive that can be seen on a desktop display.

Bonus tip: Stop cover block image becoming blurry on mobile

Sometimes, especially when the settings in the cover block are set to show a tall image, the image may blur on a mobile phone. I found the solution which works for me in this GitHub thread. Scroll down a while, and you will find the following code. Props to HUisHU-Sebastian’s comment on this GitHub thread.

PHP code added by using the Code Snippets plugin

function gb_gh_prevent_responsive_images_on_cover_block( $original_response, $image, $context, $attachment_id ){
	$processor = new WP_HTML_Tag_Processor($image);
	if( $processor->next_tag('img') && $processor->has_class( 'wp-block-cover__image-background' )){
		return false;
	}
	return $original_response;
}
add_filter( 'wp_img_tag_add_srcset_and_sizes_attr', 'gb_gh_prevent_responsive_images_on_cover_block', 10, 4 );

If you have any problems with the above PHP code, I suggest you copy and paste it directly from the GitHub thread linked to above.

Have you been affected by any of the issues above and did the the fix solve the issue? I’d love to see your comments below.

Comments are welcome and moderated.

The link to the contact page (should you wish to send a private message) is at the foot of this page.

If you need to send me an image, please use the "Contact" link at the foot of this page and I will reply to you from my email address.

Here is the link to the website comments policy: Comments Policy.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top