Skip to content

Instantly share code, notes, and snippets.

View richtabor's full-sized avatar

Rich Tabor richtabor

View GitHub Profile
/**
* Block Editor Settings.
* Add custom colors and gradients to the editor.
*/
function tabor_add_colors_and_gradients() {
$colors = array(
'primary' => '#db1c7d',
'secondary' => '#a528f0',
'tertiary' => '#90cbff',
<?php
/**
* Title: Content-only Test
* Slug: prefix/content-only-test
*/
?>
<!-- wp:group {"templateLock": "contentOnly", "align":"wide","layout":{"type":"constrained","wideSize":"2000px"}} -->
<div class="wp-block-group alignwide"><!-- wp:columns -->
<div class="wp-block-columns"><!-- wp:column -->
<div class="wp-block-column"><!-- wp:image {"id":231,"sizeSlug":"large","linkDestination":"none"} -->
@richtabor
richtabor / starter-content-custom-logo.php
Last active December 10, 2023 22:34
Adding a custom logo to a WordPress theme's starter content.
<?php
/**
* Theme defaults and support for WordPress features.
*/
function prefix_setup() {
/*
* Define starter content for the theme.
* See: https://make.wordpress.org/core/2016/11/30/starter-content-for-themes-in-4-7/
*/
<?php
if ( has_block( 'blockgallery/masonry' ) ) {
// Do something, if the Block Gallery Masonry block is added to this page.
}
wp.domReady( function() {
wp.blocks.registerBlockVariation( 'coblocks/form', {
name: 'event-registration',
title: 'Event Registration',
icon: '<svg height="48" viewBox="0 0 48 48" width="48" xmlns="http://www.w3.org/2000/svg"><path d="m18 10h-14v2h14zm2-8h-1v-2h-2v2h-12v-2h-2v2h-1c-1.11 0-1.99.9-1.99 2l-.01 16c0 1.1.89 2 2 2h18c1.1 0 2-.9 2-2v-16c0-1.1-.9-2-2-2zm0 18h-18v-13h18zm-5-5h-6-5v2h11z" transform="translate(13 14)"/></svg>',
innerBlocks: [
[ 'coblocks/field-name', { label: 'Full name', hasLastName: true } ],
[ 'coblocks/field-email', { required: true } ],
[ 'coblocks/field-radio', { label: 'How do you use WordPress?', required: true, options: [ 'I write', 'I design', 'I develop', 'I manage', 'I am new to WordPress!'] } ],
[ 'coblocks/field-checkbox', { label: 'I’m on a gluten-free diet', options: [ 'Yes', 'No' ], required: true } ],
function block_variation_example_enqueue() {
wp_enqueue_script(
'block-variation-example-script',
plugins_url( 'index.js', __FILE__ ),
array( 'wp-blocks', 'wp-dom-ready', 'wp-edit-post' ),
filemtime( plugin_dir_path( __FILE__ ) . '/block-variation-example.js' )
);
}
add_action( 'enqueue_block_editor_assets', 'block_variation_example_enqueue' );
function tabor_register_block_categories() {
if ( class_exists( 'WP_Block_Patterns_Registry' ) ) {
register_block_pattern_category(
'hero',
array( 'label' => _x( 'Hero', 'Block pattern category', 'textdomain' ) )
);
}
}
File path for a pre WordPress 4.7 asset:
<img src="<?php echo get_template_directory_uri(); ?>/images/filename.png" />
File path for a WordPress 4.7 + asset:
<img src="<?php echo get_theme_file_uri( ‘/images/filename.png’ ); ?>" />
<?php
/**
* Toggle Customizer Control
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
<!-- wp:group {"align":"full","backgroundColor":"orange","textColor":"black"} -->
<div class="wp-block-group alignfull has-black-color has-orange-background-color has-text-color has-background"><div class="wp-block-group__inner-container"><!-- wp:columns {"align":"wide"} -->
<div class="wp-block-columns alignwide"><!-- wp:column -->
<div class="wp-block-column"><!-- wp:paragraph {"fontSize":"huge"} -->
<p class="has-huge-font-size">1</p>
<!-- /wp:paragraph -->
<!-- wp:heading {"level":3,"fontSize":"extra-large"} -->
<h3 class="has-extra-large-font-size">Create</h3>
<!-- /wp:heading -->