Skip to content

Instantly share code, notes, and snippets.

@thoriqmacto
Created April 17, 2024 11:17
Show Gist options
  • Save thoriqmacto/30e6066a3a408c9b86ece8cb1338b7e4 to your computer and use it in GitHub Desktop.
Save thoriqmacto/30e6066a3a408c9b86ece8cb1338b7e4 to your computer and use it in GitHub Desktop.
Wordpress block variation registration code for post-featured-image to include caption automatically.
// Define the custom block variation
wp.blocks.registerBlockVariation(
'core/post-featured-image', // Base block type
{
name: 'sotp/post-featured-image', // Variation name
title: 'Post Featured Image + Caption', // Variation title
description: 'Displays the post\'s featured image with caption.', // Variation description
attributes: {
namespace: 'sotp_post_featured_image', // Custom attribute namespace
className: 'sotp-post-featured-image' // Custom class name
},
scope: ['inserter'] // Block variation is available only in the inserter
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment