Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Registering Block Styles in TT2 Child theme #294

Closed
tinjure20 opened this issue Dec 13, 2021 · 4 comments
Closed

Registering Block Styles in TT2 Child theme #294

tinjure20 opened this issue Dec 13, 2021 · 4 comments
Labels
[Type] Question Further information is requested

Comments

@tinjure20
Copy link

Description
I have been playing with TT2 child themes with an aim to customize one of the TT2 child themes example and use in my personal project site.

One of the thing I am trying to do is register block styles in TT2 child theme to style some blocks differently via TT2 child style.css. Following TT1 Blocks, I was able to register block styles in TT2 theme and style via its style.css (see screenshot below).
TT2

However, it failed to register the similar block style in TT2-swiss child using the same codes (see below).

if ( function_exists( 'register_block_style' ) ) {
	
	function twenty_twenty_two_register_block_styles() {
		// Separator: Thick.
		register_block_style(
			'core/separator',
			array(
				'name'  => 'tt2-wide-thick',
				'label' => esc_html__( 'Wide Thick', 'twentytwentytwo' ),
			)
		);
	}
	add_action( 'init', 'twenty_twenty_two_register_block_styles' );
}

In TT2-swiss I created /inc folder and copied the same block-styles.php from TT2 and appended require statement in TT2-swiss functions.php file. I was wondering whether this was related to my local environment and it can be reproduced by others.

A request to @kjellr: an example of registering block-syle.php and styling via child style.css would greatly benefit for beginners to try and personalize TT2 child themes.

@kjellr kjellr added the [Type] Question Further information is requested label Dec 13, 2021
@tinjure20
Copy link
Author

After reviewing code examples from Automattic Blockbase and its child themes (Quadrant, Geologist, ..) I realized that I had to use get_stylesheet_directory() instead of get_template_directory() in my TT2-swiss functions.php require statement. That seem to correct the problem. I have not yet fully tested using child theme style.css for block styling but hopefully should work!

I thought to share my solution for the benefit of others.

@scruffian
Copy link
Collaborator

Adding block styles via the theme is not considered best practice - particularly because users will lose that style when they switch themes. It might be better to suggest these as block styles in Gutenberg.

@tinjure20
Copy link
Author

Thanks. Just for clarification, in this particular example, I was adding codes directly in TT2 theme for TESTING PURPOSE ONLY because the theme does not include registered block-styles.

@scruffian
Copy link
Collaborator

Ah I see, makes sense :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
[Type] Question Further information is requested
3 participants