Last active
May 22, 2025 19:19
-
-
Save karks88/5ff17723ae710bf0312dca49cf0470c7 to your computer and use it in GitHub Desktop.
Plugin: My Custom WordPress Block Style Variations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Plugin Name: My Custom Block Variations | |
| * Description: Adds custom block style variations to the WordPress block editor. | |
| * Author: Eric Karkovack | |
| * Author URI: https://speckyboy.com/ | |
| * Version: 1.0.0 | |
| * Requires at least: 6.6 | |
| * Requires PHP: 7.4 | |
| */ | |
| // Don't allow direct access to the plugin file. | |
| defined('ABSPATH') || exit; | |
| // Custom function to register block style variations. | |
| function mcbv_register_block_styles() { | |
| // Add block style variations here. See: https://developer.wordpress.org/block-editor/reference-guides/block-api/block-styles/#server-side-registration-helper | |
| register_block_style( | |
| array( 'core/button' ), // We're adding styles to the button block. | |
| array( | |
| 'name' => 'unicorn', | |
| 'label' => __( 'Unicorn', 'mcbv' ), // The name of our style and the plugin's text domain. | |
| 'style_data'=> array( | |
| 'border' => array( // Define border styles. | |
| 'color' => '#9300a0', | |
| 'style' => 'solid', | |
| 'width' => '2px', | |
| 'radius' => '0px' | |
| ), | |
| 'color' => array( // Define color styles. | |
| 'background' => '#B516C3', | |
| 'gradient' => 'linear-gradient(90deg,rgba(181, 22, 195, 1) 0%, rgba(108, 22, 195, 1) 50%, rgba(22, 51, 195, 1) 100%);', | |
| 'text' => '#FFFFFF', | |
| ), | |
| 'typography' => array( // Define typography styles. | |
| 'fontStyle' => 'normal', | |
| 'fontWeight' => 'bold' | |
| ), | |
| ) | |
| ) | |
| ); | |
| } | |
| // Initialize the custom function. | |
| add_action( 'init', 'mcbv_register_block_styles' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment