Skip to content

Instantly share code, notes, and snippets.

Avatar

Justin Tadlock justintadlock

View GitHub Profile
@justintadlock
justintadlock / theme.json
Created May 31, 2021
Block theme color naming scheme
View theme.json
{
"settings": {
"defaults": {
"color": {
"palette": [
{
"slug": "transparent",
"color": "transparent",
"name" : "Transparent"
},
@justintadlock
justintadlock / fruity-fruit.php
Last active Jul 13, 2022
Saving multiple meta values for a single key with a meta box.
View fruity-fruit.php
<?php
/*
Plugin Name: Fruity Fruit
Description: An example plugin to test saving multiple meta values.
*/
add_action( 'add_meta_boxes_post', 'fruity_fruit_add_meta_boxes' );
add_action( 'save_post', 'fruity_fruit_save_meta', 10, 2 );
function fruity_fruit_add_meta_boxes() {
@justintadlock
justintadlock / wp-recipe-card-pattern.html
Created Mar 18, 2022
WordPress block code for creating a recipe card pattern.
View wp-recipe-card-pattern.html
<!-- wp:group {"style":{"spacing":{"blockGap":"0px"},"border":{"style":"solid","width":"2px"}},"borderColor":"black"} -->
<div class="wp-block-group has-border-color has-black-border-color" style="border-style:solid;border-width:2px"><!-- wp:image {"align":"center","id":10590,"sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image aligncenter size-large"><img src="http://localhost/wp-content/uploads/2022/03/image-2-1024x605.png" alt="" class="wp-image-10590"/></figure>
<!-- /wp:image -->
<!-- wp:group {"style":{"spacing":{"padding":{"top":"2rem","right":"2rem","bottom":"2rem","left":"2rem"}}}} -->
<div class="wp-block-group" style="padding-top:2rem;padding-right:2rem;padding-bottom:2rem;padding-left:2rem"><!-- wp:heading -->
<h2>Veggie Pizza</h2>
<!-- /wp:heading -->
@justintadlock
justintadlock / cover-offset-styles.php
Created Jun 4, 2021
Offset left and right Cover block styles
View cover-offset-styles.php
<?php
add_action( 'init', function() {
register_block_style( 'core/cover', [
'name' => 'offset-left',
'label' => __( 'Offset Left' ),
'inline_style' =>
'.wp-block-cover.is-style-offset-left > .wp-block-cover__inner-container {
background-color: inherit;
@justintadlock
justintadlock / book-review-intro-card.html
Created Apr 2, 2022
Book review intro card using WordPress blocks.
View book-review-intro-card.html
<!-- wp:group {"align":"wide","style":{"color":{"background":"#384a5c"},"spacing":{"padding":{"top":"2rem","right":"2rem","bottom":"2rem","left":"2rem"}}},"textColor":"white"} -->
<div class="wp-block-group alignwide has-white-color has-text-color has-background" style="background-color:#384a5c;padding-top:2rem;padding-right:2rem;padding-bottom:2rem;padding-left:2rem"><!-- wp:media-text {"mediaId":6222,"mediaLink":"http://localhost/?attachment_id=6222","mediaType":"image","mediaWidth":40,"imageFill":false,"backgroundColor":"neutral-100"} -->
<div class="wp-block-media-text alignwide is-stacked-on-mobile has-neutral-100-background-color has-background" style="grid-template-columns:40% auto"><figure class="wp-block-media-text__media"><img src="http://localhost/wp-content/uploads/2021/06/ff-book-cover.jpg" alt="" class="wp-image-6222 size-full"/></figure><div class="wp-block-media-text__content"><!-- wp:group {"style":{"spacing":{"blockGap":{"top":"2rem","left":"2rem"}}}} -->
<div class="wp-block-group"><!-- wp:
@justintadlock
justintadlock / book-card.html
Created Apr 2, 2022
Book card created with WordPress blocks.
View book-card.html
<!-- wp:group {"align":"wide","style":{"color":{"background":"#384a5c"},"spacing":{"padding":{"top":"2rem","right":"2rem","bottom":"2rem","left":"2rem"}}},"textColor":"white"} -->
<div class="wp-block-group alignwide has-white-color has-text-color has-background" style="background-color:#384a5c;padding-top:2rem;padding-right:2rem;padding-bottom:2rem;padding-left:2rem"><!-- wp:media-text {"mediaId":6222,"mediaLink":"http://localhost/book-review/ff-book-cover/","mediaType":"image","mediaWidth":35} -->
<div class="wp-block-media-text alignwide is-stacked-on-mobile" style="grid-template-columns:35% auto"><figure class="wp-block-media-text__media"><img src="http://localhost/wp-content/uploads/2021/06/ff-book-cover.jpg" alt="" class="wp-image-6222 size-full"/></figure><div class="wp-block-media-text__content"><!-- wp:group {"style":{"spacing":{"blockGap":{"top":"2rem","left":"2rem"}}}} -->
<div class="wp-block-group"><!-- wp:heading -->
<h2>Lightning Bugs</h2>
<!-- /wp:heading -->
<!-- wp:paragraph -->
<p>A guy. A
@justintadlock
justintadlock / register-post-type.php
Last active Feb 17, 2022
Help file when registering post types.
View register-post-type.php
<?php
# Register custom post types on the 'init' hook.
add_action( 'init', 'my_register_post_types' );
/**
* Registers post types needed by the plugin.
*
* @since 1.0.0
* @access public
@justintadlock
justintadlock / wood-frame.html
Created Dec 19, 2021
Block pattern for a wooden picture frame using Jeff Chandler's picture.
View wood-frame.html
<!-- wp:cover {"url":"http://localhost/wp-content/uploads/2021/12/Wood066_1K_Color.jpg","id":8923,"isRepeated":true,"dimRatio":30,"overlayColor":"foreground","minHeight":0,"isDark":false,"align":"wide","style":{"spacing":{"padding":{"top":"0.25rem","right":"0.25rem","bottom":"0.25rem","left":"0.25rem"}}}} -->
<div class="wp-block-cover alignwide is-light is-repeated" style="padding-top:0.25rem;padding-right:0.25rem;padding-bottom:0.25rem;padding-left:0.25rem;background-image:url(http://localhost/wp-content/uploads/2021/12/Wood066_1K_Color.jpg)"><span aria-hidden="true" class="has-foreground-background-color has-background-dim-30 wp-block-cover__gradient-background has-background-dim"></span><div class="wp-block-cover__inner-container"><!-- wp:group {"align":"wide","style":{"border":{"width":"2px","style":"solid"}},"borderColor":"foreground"} -->
<div class="wp-block-group alignwide has-border-color has-foreground-border-color" style="border-style:solid;border-width:2px"><!-- wp:cover {"url":"http://localhost/
@justintadlock
justintadlock / pattern-cover-audio-social.html
Created Dec 29, 2021
Cover block pattern with audio player and social links.
View pattern-cover-audio-social.html
<!-- wp:cover {"url":"https://pd.w.org/2021/12/63161c1f1d83e8218.20535107-2048x1365.jpg","id":8980,"dimRatio":70,"overlayColor":"foreground","minHeight":320,"contentPosition":"center center"} -->
<div class="wp-block-cover" style="min-height:320px"><span aria-hidden="true" class="has-foreground-background-color has-background-dim-70 wp-block-cover__gradient-background has-background-dim"></span><img class="wp-block-cover__image-background wp-image-8980" alt="" src="https://pd.w.org/2021/12/63161c1f1d83e8218.20535107-2048x1365.jpg" data-object-fit="cover"/><div class="wp-block-cover__inner-container"><!-- wp:group {"borderColor":"background"} -->
<div class="wp-block-group has-border-color has-background-border-color"><!-- wp:cover {"dimRatio":20,"minHeight":320,"customGradient":"linear-gradient(135deg,rgb(255,206,236) 0%,rgb(152,150,240) 100%)","contentPosition":"center center","isDark":false,"style":{"spacing":{"padding":{"top":"2rem","right":"2rem","bottom":"2rem","left":"2rem"}}}} -->
<div class="wp-block-
@justintadlock
justintadlock / functions.php
Created Apr 29, 2021
Remove block-templates support from Gutenberg.
View functions.php
<?php
// Drop the below in theme functions.php.
add_action( 'after_setup_theme', function() {
remove_theme_support( 'block-templates' );
} );