Skip to content

Instantly share code, notes, and snippets.

@alexmustin
Created August 5, 2020 19:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexmustin/b412d660fba92f25a55677fd23acd207 to your computer and use it in GitHub Desktop.
Save alexmustin/b412d660fba92f25a55677fd23acd207 to your computer and use it in GitHub Desktop.
WP - Add block style variations
jQuery(document).ready(function($) {
// Add 'Semibold' style to Paragraph blocks
wp.blocks.registerBlockStyle("core/paragraph", {
name: "semibold",
label: "Semibold"
});
// Add 'Black' style to Paragraph blocks
wp.blocks.registerBlockStyle("core/paragraph", {
name: "weightblack",
label: "Black"
});
});
p.is-style-semibold {
font-weight: 600 !important;
}
p.is-style-weightblack {
font-weight: 800 !important;
}
<?php
// Enqueue the variations JS.
add_action( 'enqueue_block_editor_assets', 'block_editor_variations_js' );
function block_editor_variations_js() {
wp_enqueue_script( 'blockstylevariations-js', get_stylesheet_directory_uri() . '/js/block-style-variations.js', array( 'jquery' ), '1.0', true );
}
// Enqueue custom Block Styles.
add_action( 'enqueue_block_assets', 'custom_block_styles_css' );
function custom_block_styles_css() {
wp_enqueue_style( 'custom-block-styles', get_stylesheet_directory_uri() . '/css/custom-block-styles.css' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment