Coloured Backgrounds in Gutenberg

To add a splash of colour behind a paragraph of text, you go over to the sidebar and you will see two tabs. One says Colour Settings and the other says Advanced. 

When you open the Colour Settings you see two palettes of colours. Depending on which palette you choose, you can change the colour of the text and/or the colour of the background to the text.

You can choose one of the predefined colours that are there or you can click on the multi-coloured circle at the end of the swatch of colours and make any colour you want.

Here is a short paragraph with the background colour a nice rose pink using the hexadecimal #ffdfe0

When you add a quote, however, the Colour Settings tab disappears leaving only the Advanced tab.

Open the Advanced tab and you will see that it says Additional CSS Class.

I wondered what it meant until I realised it was an invitation to create a CSS class.

The little that I know about classes is that you should name them something that is not likely to have been used elsewhere in the main code. So I named it ‘quote-thing’. Catchy, eh?

Stage 2 was to add the CSS to the CSS section in the Customiser. It has to refer to the class and it has to tell the class what to do. So I said it should make the background a specific colour #ebf2f5 – a pale blueish colour.

And I wanted to put a bit of padding around the quote so that it didn’t look like it was sitting in a straightjacket.

Here is the code:

/* background colour for quote */
.quote-thing {
background: #ebf2f5;
padding-top: 15px;
padding-right: 15px;
padding-bottom: 5px;
padding-left: 15px;
}

And here are two quotes attributed to Fyodor Dostoyevsky:

The greatest happiness is to know the source of unhappiness.

It is better to be unhappy and know the worst, than to be happy in a fool’s paradise.

The second Dostoyevsky quote is interesting and has been used in many a book and film as well as it appearing in real life. It also goes to show that there is nothing new under the sun. The Buddha said:

‘It is better to live one day seeing the rise and fall of things, than to live a hundred years without ever seeing the rise and fall of things.’

Notice that I didn’t add the CSS class to this quote, so it does not have a coloured background. If I gave it another CSS class name and a different hexadecimal then it could have a different colour background to the Dostoyevsky quote.

Disabling Gutenberg Blocks

With Disable Gutenberg blocks by Danny Cooper, you can disable the blocks you don’t need.

On the plugin page in the WordPress repository there is a list of the block plugins that it supports. 

I am not sure what ‘disable’ means. Having listened to Joost speaking yesterday on WP Sessions, I understand that the problem with blocks is that if you have a number of collections of blocks, then they are all called on every page and that will slow down your site.

Does Danny Cooper’s Disable Gutenberg Blocks plugin solve this issue? I asked him, and he replied:

Block Managers are unlikely to offer any performance gains as ‘Block Collections’ will load all their CSS/JS regardless of which blocks are used.

A block library built into WordPress Core which only includes simple standalone blocks would help for those times you want something small without all the bloat.

For more complex page builders there is always going to be some performance concerns, just like you already have with Elementor and the like.

Columns In Gutenberg

I am using the two-column block here. Choosing it brings up two blocks side by side. Clicking on the + icon allows you to choose what you want in the block. I chose ‘paragraph’ (i.e. text) and this is the result.

’Twas brillig, and the slithy toves
Did gyre and gimble in the wabe:
All mimsy were the borogoves,
And the mome raths outgrabe.

“Beware the Jabberwock, my son!
The jaws that bite, the claws that catch!
Beware the Jubjub bird, and shun
The frumious Bandersnatch!”

He took his vorpal sword in hand;
Long time the manxome foe he sought—
So rested he by the Tumtum tree
And stood awhile in thought.

And, as in uffish thought he stood,
The Jabberwock, with eyes of flame,
Came whiffling through the tulgey wood,
And burbled as it came!

One, two! One, two! And through and through
The vorpal blade went snicker-snack!
He left it dead, and with its head
He went galumphing back.

“And hast thou slain the Jabberwock?
Come to my arms, my beamish boy!
O frabjous day! Callooh! Callay!”
He chortled in his joy.

’Twas brillig, and the slithy toves
Did gyre and gimble in the wabe:
All mimsy were the borogoves,
And the mome raths outgrabe.

This is something I wrote a while ago when column blocks worked differently.

It seems that the way to add text within a column is to write and then when one gets to the point at which one wants to change to the adjoining column, one starts typing in the adjoining column – 

like this and then simply continues typing. The question is what happens if the amount of text one types in the adjoining column outstrips the amount of text in the first column? Can one move these little blocks of text within the columns around?

We are about to find out because now I am typing in the right-hand column, and I want the text in the paragraph above to shift to the left-hand column.

And yes, with a bit of faffing about I was able to move the text to the left hand column and continue typing here.

So having done it once, I now want to do it again with the text block that begins with the words ‘We are about to..’

So – I will find out whether I am getting the hang of it or whether the exact mechanism remains a mystery.

And the answer again is that I am now an experienced and somewhat accomplished mover of column blocks.

Twenty Nineteen Theme Full Width Content

The default setting for the text for the Twenty Nineteen theme stretches only partway across the page, and yet the theme does not allow for sidebar widgets.

The result is a theme with text that takes up part of the page, with half the page empty all the way down it.

I wasn’t interested in trying to find a way to introduce a sidebar with widgets. I wanted the text to take up the full width, and this is the CSS I am using to accomplish that.

/* to make page content full width */
body.page .entry .entry-content > *, .entry .entry-summary > * {
        max-width: none;
}

/* to make posts content full width */
.entry .entry-content p
{
        max-width: none;
}

/* to make shop content full width */
.woocommerce .content-area .site-main
{
        max-width: none;
}

Here’s the raw code: 2019-full-width-text

Hide Product Categories

admin on January 11, 2019

If you want to pre-approve your customers (such as in a trade-only shop) then you might want to disable the visibility of pricing as the ability for visitors to buy your products.

Catalog Visibility Options

The Catalog Visibility Options plugin will do this and also let you choose which user roles can see products and product categories. 

Therefore, if you want to take a category out of the shop, use the plugin to do that.

PHP code

Otherwise there is this code that I saw on Business Bloomer but the code was in the comments, and is from Jonathan from Inspired Earth

function custom_pre_get_posts_query( $q ) { $tax_query = (array) $q->get( 'tax_query' ); $tax_query[] = array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => array( 'CATEGORY-TO-HIDE' ), // Don't display products in the this category on the shop page. 'operator' => 'NOT IN' ); $q->set( 'tax_query', $tax_query ); } add_action( 'woocommerce_product_query', 'custom_pre_get_posts_query' );

Here is the raw code

Where to put the code

I use the Code Snippets plugin (it’s in the WordPress repository) to contain snippets of php.

Debug, Health Check & Troubleshooting

The Health Check & Troubleshooting plugin is made by the WordPress.org community.

It has a debug function that checks common configuration errors and known issues in a WordPress setup, and highlights them.

It doesn’t solve them, but it gives you the information to tackle the issue.

Theme and Plugin Conflicts

When you activate the Troubleshooting feature, it reverts your site to a default WordPress theme like Twenty Seventeen and deactivates all your plugins.

You can then turn your chosen theme back on to see whether the issue reasserts itself.

If it does then you know it’s a theme-specific issue.

If not, then you can re-activate your plugins one by one until you see the issue reappear. In that way you can resolve plugin conflict issues.

The neat part is that it does it only for you as the logged in admin. Anyone visiting the site sees your usual setup.

Take a full backup before you start…