Skip to content

Instantly share code, notes, and snippets.

@damiencarbery
Last active March 15, 2021 11:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save damiencarbery/00aa77cecebfc3dd7b750eba7ee58ea7 to your computer and use it in GitHub Desktop.
Save damiencarbery/00aa77cecebfc3dd7b750eba7ee58ea7 to your computer and use it in GitHub Desktop.
Demo of Genesis Custom Blocks - A simple custom block delivered in a plugin. https://www.damiencarbery.com/2020/09/demo-of-genesis-custom-blocks/
<details class="genesis-custom-block <?php block_field('className'); ?>">
<summary class="item-title"><?php block_field( 'title' ); ?></summary>
<div class="item-content"><?php block_field( 'content' ); ?></div>
</details>
<div class="genesis-custom-block <?php block_field('className'); ?>">
<h3 class="item-title"><?php block_field( 'title' ); ?></h3>
<div class="item-subtitle"><p><?php block_field( 'subtitle' ); ?></p></div>
</div>
<?php
/*
Plugin Name: Accordion block - Genesis Custom Blocks
Plugin URI: https://www.damiencarbery.com
Description: A simple accordion block created with Genesis Custom Blocks plugin.
Author: Damien Carbery
Version: 0.1
*/
add_filter( 'genesis_custom_blocks_template_path', 'dcwd_gcb_accordion_block_template_path', 10, 2 );
function dcwd_gcb_accordion_block_template_path( $path, $template_names ) {
//error_log( 'Path: ' . var_export( $path, true ) );
//error_log( 'Template names: ' . var_export( $template_names, true ) );
foreach ( (array) $template_names as $template_name ) {
// If the Accordion block (preview or front end), return this directory.
if (( 'blocks/block-accordion-block.php' == $template_name ) ||
( 'blocks/preview-accordion-block.php' == $template_name )) {
return __DIR__;
}
}
return $path;
}
<?php
/*
Plugin Name: Title/Subtitle block - Genesis Custom Blocks
Plugin URI: https://www.damiencarbery.com
Description: A simple title/subtitle block created with Genesis Custom Blocks plugin.
Author: Damien Carbery
Version: 0.1
*/
add_filter( 'genesis_custom_blocks_template_path', 'dcwd_gcb_title_subtitle_block_template_path', 10, 2 );
function dcwd_gcb_title_subtitle_block_template_path( $path, $template_names ) {
foreach ( (array) $template_names as $template_name ) {
if ( 'blocks/block-title-subtitle-block.php' == $template_name ) {
return __DIR__;
}
}
return $path;
}
<details open="true" class="genesis-custom-block <?php block_field('className'); ?>">
<summary class="item-title"><?php block_field( 'title' ); ?></summary>
<div class="item-content"><?php block_field( 'content' ); ?></div>
</details>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment