How to know whether you are editing a page or a post?

You can use the admin_body_class hook to add your own CSS classes. For example (if you’re using Gutenberg): function pb_admin_body_class($classes) { $screen = get_current_screen(); if (!$screen->is_block_editor()) { return $classes; } $post_id = isset($_GET[‘post’]) ? intval($_GET[‘post’]) : false; $post_type = get_post_type($post_id); if ($post_type) { $classes .= $post_type; } return $classes; } add_filter(‘admin_body_class’, ‘pb_admin_body_class’);

InnerBlocks breaks Flexbox and CSS Grid styles

You can eliminate the wrapping containers abandoning InnerBlocks and instead using the useInnerBlocksProps hook which is how the blocks that come with core do it. This will allow your block markup to match the frontend without the editor wrapping things in additional tags. If we look at the official buttons block: import { BlockControls, useBlockProps, … Read more

Adding an html wrapper to a custom Block Pattern

The group block comes to mind as an out of the box pattern wrapper with a custom class mywrapper: <!– wp:group {“className”:”mywrapper”} –> <div class=”wp-block-group mywrapper”><div class=”wp-block-group__inner-container”> …pattern… </div></div> <!– /wp:group –> Theoretically one can use the custom html block as a pattern, like: <!– wp:html –> <div class=”mywrappper”> <h1 class=”has-text-align-center”>Block 1</h1> <h2 class=”has-text-align-center”>Block 2</h2> … Read more

Show date post published in Gutenberg component

I was able to get there by doing the following. import * as wpDate from “@wordpress/date”; You can find the very limited documentation on that here: https://developer.wordpress.org/block-editor/reference-guides/packages/packages-date/ I was able to use the following: const post = wp.data.select(“core/editor”).getCurrentPost(); const postDate = wpDate.format(“d|m|Y”, post.date); Then, when I needed it: <div> <RichText className=”snug huge” placeholder=”Your title here” … Read more

Determine if block has already been registered

EDIT I just realized you’re doing this on the PHP side. There is a class called WP_Block_Type_Registry that you can use to see what is already registered: $registry = WP_Block_Type_Registry::get_instance(); if ( ! $registry->get_registered( ‘foo/column’ ) ) { // YOUR CODE } Gutenberg should fire a console error if a block has already been registered. … Read more

JSON File in Gutenberg

You can accomplish this with the good ol’ wp_localize_script. Step 1: When you register your blocks script, you already will do something like this: wp_register_script( ‘my-awesome-block’, plugins_url(‘/blocks/dist/blocks.build.js’, __FILE__), array(‘wp-blocks’, ‘wp-element’,’wp-editor’,’wp-components’,’lodash’), filemtime(plugin_dir_path(__FILE__).’blocks/dist/blocks.build.js’) ); After this (within the same function) insert: //Do whatever to parse the json-file or get the categories, get them into a nice array … Read more

Gutenberg Multiple InnerBlocks

You can (at the moment) not use InnerBlocks more than once within a block. However, you can bypass this by using a template for your InnerBlocks that contain Blocks which support InnerBlocks instead, like the core/column block. Like this: wp.element.createElement(InnerBlocks, { template: [[‘core/column’,{},[[‘core/paragraph’,{‘placeholder’:’Inhalt linke Spalte’}]]],[‘core/column’,{},[[‘core/paragraph’,{‘placeholder’:’Inhalt rechte Spalte’}]]]], templateLock: “all”, allowedBlocks: [‘core/column’]}); Some time ago, i … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)