Building a Custom Button Block
Learn to create a PHP class to generalize the block creation process.
We will create a block that adds a button with our theme's styling.
Using a PHP class for block registration
Since we will be defining multiple blocks for our theme, instead of registering them one by one, we can create a PHP class to reduce code duplication. This will also help avoid naming conflicts with other functions and variables of WordPress or any third party plugins.
In functions.php
, create a class called ExcellenceBlock
. The class will have a __construct
function which includes the action and filter hooks.
Get hands-on with 1300+ tech skills courses.