Skip to content

How to change the height and width of a block in WordPress

WordPress, one of the most popular website building platforms in the world, gives users fully customizable control over the look and feel of their website. In this article, we will go through the different methods to change the block height and width in WordPress, both through code and using plugins.

Introduction to blocks in WordPress

Since version 5.0, WordPress introduced a new block editor known as Gutenberg. This editor allows users to create and format content using blocks. Each block can be individually formatted and styled, giving the user more control over the look of their site.

1. Changing the height and width of a block using the Gutenberg block editor

In the Gutenberg block editor, we can resize a block directly using built-in options. However, it should be noted that not all blocks have resizing options.

To resize a block:

  1. Click on the block you want to modify.
  2. In the side panel on the right you will see the settings for this block.
  3. Some blocks, such as an image, have options to change the width and height directly in these settings.
  4. If resizing options are not available, you will need to use CSS or PHP to resize the block.

2. Changing the height and width of a block with CSS

CSS (Cascading Style Sheets) is a language used to describe the appearance of a document written in HTML or XML. You can use it to change the height and width of blocks in WordPress.

To resize a block with CSS:

  1. Click on the block you want to modify.
  2. In the side panel on the right, go to the "Advanced" section.
  3. In the "Additional CSS Classes" section, enter a unique class name for the block.
  4. Then go to Appearance > CSS Editor in your WordPress admin panel.
  5. Enter the following CSS code, replacing “your-class” with the class name you gave the block and “your-width” and “your-height” with your preferred dimensions:
.your-class { width: your-width; height: your-height; }

3. Changing the height and width of a block using PHP

If you want to resize the blocks across the page, it might be more convenient to do it with PHP. However, you must be aware that errors in the PHP code can cause serious problems on your website.

function change_block_size() { echo '
   .your-class {
      width: your-width;
      height: your-height;
   }
   '; } add_action('wp_footer', 'change_block_size');

This code needs to be pasted into the functions.php file in your WordPress theme. Remember to replace “your-class”, “your-width” and “your-height” with the appropriate values.

4. Changing block height and width with plugins

There are many WordPress plugins that allow you to easily resize blocks. For example, “Advanced Gutenberg” gives users additional tools to control Gutenberg blocks, including the ability to change the height and width of blocks.

To resize a block using “Advanced Gutenberg”:

  1. Install and activate the “Advanced Gutenberg” plugin from the WordPress repository.
  2. Go to “Advanced Gutenberg” > “Block Configuration” in the admin panel.
  3. Select the block you want to resize.
  4. In the "Block Styles" section, you can change the height and width of the block.

Summary

As you can see, there are many ways to change the height and width of a block in WordPress. Each method has its pros and cons, so your best bet is to choose the one that best suits your needs and comfort level with the technology. Remember, however, that it's always a good idea to back up your page before making any code changes.

Check out the offer of 1500+ Premium WordPress plugins and themes!