Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
Working from home

Ryan Welcher ryanwelcher

:octocat:
Working from home
View GitHub Profile
View edit.js
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { useBlockProps, InspectorControls } from '@wordpress/block-editor';
import { PanelBody, ComboboxControl } from '@wordpress/components';
import { useEntityRecords } from '@wordpress/core-data';
export default function Edit( {
attributes: { blockTaxonomyTerm },
View block.json
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2,
"name": "create-block/mol-custom-blocks",
"version": "0.1.0",
"title": "Monte Logic's Custom Blocks",
"category": "text",
"icon": "flag",
"description": "A Gutenberg block to show your pride! This block enables you to type text and style it with the color font Gilbert from Type with Pride.",
"attributes": {
@ryanwelcher
ryanwelcher / block.json
Created May 20, 2022
Defining default values for Background color, text color, link color, padding and margin for custom blocks
View block.json
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2,
"name": "create-block/block-supports-test",
"version": "0.1.0",
"title": "Block Supports Test",
"category": "widgets",
"icon": "smiley",
"description": "Example block written with ESNext standard and JSX support – build step required.",
"attributes":{
@ryanwelcher
ryanwelcher / webfonts-tt2-example.json
Created Apr 29, 2022
WordPress 6.0 Example: Webfonts API Registering a font from theme.json
View webfonts-tt2-example.json
"fontFamilies": [
{
"fontFamily": "-apple-system,BlinkMacSystemFont,\"Segoe UI\",Roboto,Oxygen-Sans,Ubuntu,Cantarell,\"Helvetica Neue\",sans-serif",
"name": "System Font",
"slug": "system-font"
},
{
"fontFamily": "\"Source Serif Pero\", serif",
"name": "Source Serif Pero",
"slug": "source-serif-pero",
@ryanwelcher
ryanwelcher / example-pattern.php
Last active Jul 19, 2022
WordPress 6.0 Example: Example pattern PHP file to register a block pattern in the /patterns directory
View example-pattern.php
<?php
/**
* Title: Example Block Pattern ( required field )
* Slug: block-pattern-example (required field)
* Description: This is an example of how to use the new /patterns directory to register a block pattern.
* Categories: featured, text
* Viewport Width: 800
* Keywords: example, block-theme, block-pattern
* Block Types: core/template-part/footer, core/post-content
* Inserter: yes
@ryanwelcher
ryanwelcher / wp-6-0-suggested-block-pattern.php
Created Apr 28, 2022
WordPress 6.0 Example: Allowing a block patter to be show as a suggestion on new Pages.
View wp-6-0-suggested-block-pattern.php
<?php
/**
* Example showing how to allow a block pattern to be shown as a suggested pattern for new Pages.
*/
add_action(
'init',
function() {
register_block_pattern(
'block-pattern-suggestion-example',
array(
@ryanwelcher
ryanwelcher / wordpress-6-0-block-locking.php
Last active Jul 19, 2022
WordPress 6.0: Examples on how to restrict block locking in the UI
View wordpress-6-0-block-locking.php
<?php
/**
* Examples on restricting when blocks can be locked using the UI.
* Based on the example provided by @mamaduka in https://github.com/WordPress/gutenberg/pull/39566
*
* @see https://developer.wordpress.org/reference/hooks/block_editor_settings_all/
*/
add_filter(
'block_editor_settings_all',
function( $settings, $context ) {
@ryanwelcher
ryanwelcher / theme.json
Created Feb 8, 2022
When adding theme.json to an existing Classic Theme, these settings will stop the default color and typography controls from being enabled.
View theme.json
{
"$schema": "http://schemas.wp.org/trunk/theme.json",
"version": 2,
"settings": {
"layout": {
"contentSize": "750px"
},
"color": {
"background": false,
"custom": false,
@ryanwelcher
ryanwelcher / query-loop-locked.html
Created Feb 8, 2022
A Block Theme Template Part that provides a Query Loop block with locked Post Title and Feature Image blocks.
View query-loop-locked.html
<!-- wp:query {"queryId":1,"query":{"offset":0,"postType":"post","categoryIds":[],"tagIds":[],"order":"desc","orderBy":"date","author":"","search":"","sticky":""}} -->
<!-- wp:post-template -->
<!-- wp:post-title {"isLink":true,"lock":{"remove":true}} /-->
<!-- wp:post-featured-image {"isLink":true,"align":"wide","lock":{"remove":true}} /-->
<!-- wp:post-date /-->
<!-- wp:post-excerpt /-->
<!-- wp:separator -->
<hr class="wp-block-separator"/>
<!-- /wp:separator -->
<!-- /wp:post-template -->
@ryanwelcher
ryanwelcher / locked-query-loop-pattern.php
Last active Feb 8, 2022
A block pattern containing a Query Loop with locked Post Title and Featured Image blocks
View locked-query-loop-pattern.php
register_block_pattern(
'locking-examples/locked-query-loop',
array(
'title' => esc_html__( 'Query Loop with locked Post Title and Featured Image blocks', 'locking-examples' ),
'categories' => array( 'query' ),
'content' => '<!-- wp:query {"queryId":26,"query":{"perPage":3,"pages":0,"offset":0,"postType":"post","categoryIds":[],"tagIds":[],"order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":false}} -->
<div class="wp-block-query"><!-- wp:post-template -->
<!-- wp:post-title {"isLink":true,"lock":{"remove":true}} /-->
<!-- wp:post-featured-image {"isLink":true,"align":"wide","lock":{"remove":true}} /-->