WordPress’ block editor comes with the feature of block templates. This allows us to defined a set of blocks that will be present in the content of new pages, posts and/or custom post types. This post shows you how to use that functionality and how to use reusable blocks in templates.
Continue reading "Define block templates for new pages, posts, and custom post types"Category: WordPress snippets
Modify save function of block
Sometimes there is a block for the WordPress block editor that is almost what we want, but it would be necessary to modify the markup it saves to the database. This post shows how we can filter the save function of a block to get that done.
Continue reading "Modify save function of block"Gutenberg: wrap core block in element
Yesterday I had the problem, that the core table block is not wrapped in a div
at the frontend. Of course, it is great that no useless markup is outputted, but I needed a wrapper element for my responsive table solution. Here I show you how to wrap a core block in an element.
Create different color palettes with Gutenberg
In this post I show how to create different color palettes in Gutenberg, to – for example – allow other colors for the text than for the background.
Continue reading "Create different color palettes with Gutenberg"Using the official PHP library for the WooCommerce REST API with basic auth
If a WordPress installation is protected via .htaccess
basic auth, the requests against the WooCommerce REST API with the PHP library do not work. I did not find the GitHub issue where someone said that CURL could be used to set the login credentials, but with that information, I found a question and the answers on Stack Overflow, that helped me:
$ch = curl_init();
curl_setopt( $ch, CURLOPT_USERPWD, 'user:password' );
Code language: PHP (php)
I inserted these two lines at the beginning of my script and replaced user
and password
with the actual login data. With that, the requests against the protected installation worked.
Parallel requests against the WooCommerce API with the PHP Requests library
Two of my recent articles are about the WooCommerce REST API and the official PHP library from Automattic, which makes the usage of the API with PHP easier. This post describes a way to run multiple requests against a shop at the same time.
Continue reading "Parallel requests against the WooCommerce API with the PHP Requests library"Creating theme editor styles for Gutenberg
WordPress 5 will come with a new editor called »Gutenberg«, which is completely different from the current TinyMCE. That does not only mean change for the users, but also for theme developers, who want to modify editor styles, so it looks like in the frontend. This post shows you how that works for the new editor.
Continue reading "Creating theme editor styles for Gutenberg"Creating a WooCommerce product variation with the REST API
Like adding a product via the REST API is creating a product variation done relatively quickly – I use the PHP library for that, like in my last week’s post.
Continue reading "Creating a WooCommerce product variation with the REST API"Creating a WooCommerce product with PHP via the REST API
WooCommerce comes with a REST API that, for example, allows us to create products. Here I show you how to do this.
Continue reading "Creating a WooCommerce product with PHP via the REST API"Validating customize settings with displaying error messages
Since WordPress 4.6 it is relatively simple to add validation to customize settings, to give helpful error messages to the user. Here I show you how that works.
Continue reading "Validating customize settings with displaying error messages"