Skip to content

Instantly share code, notes, and snippets.

View colorful-tones's full-sized avatar
💓
Don’t believe the hype!

Damon Cook colorful-tones

💓
Don’t believe the hype!
View GitHub Profile
@colorful-tones
colorful-tones / acf-field-group-demo.php
Last active April 26, 2024 14:29
ACF Chat Fridays - April 26, 2024 - Block Bindings with ACF demo
add_action( 'acf/include_fields', function() {
if ( ! function_exists( 'acf_add_local_field_group' ) ) {
return;
}
acf_add_local_field_group( array(
'key' => 'group_662ae89971cc7',
'title' => 'Call to action',
'fields' => array(
array(
@colorful-tones
colorful-tones / functions-alternative-approach.php
Last active April 18, 2024 20:39
Override core/navigation block styles without using `!important` (see comment below for implementation details)
/**
* Enqueues custom block styles for the theme.
*
* This function scans the styles folder in the theme to locate block styles.
* It then enqueues each block style using the `wp_enqueue_block_style` function.
*
* @url https://developer.wordpress.org/reference/functions/wp_enqueue_block_style/
*/
function devrel_enqueue_custom_block_styles() {
@colorful-tones
colorful-tones / my_link.php
Created January 9, 2024 16:30
Parsing an ACF Link field type with defaults
@colorful-tones
colorful-tones / my-plugin.php
Last active December 6, 2023 21:35
Load JavaScript once on the page if a core block exists. As adapted from https://wordpress.stackexchange.com/a/328553
function enqueue_my_awesome_script_if_there_is_block( $content = '' ) {
if ( has_block( 'core/list' ) ) {
wp_enqueue_script(
'my-awesome-script',
plugins_url( 'hello-world.js', __FILE__ ),
array(),
'0.1.1',
true
);
}
<?php
/**
* Limit capabilities of editing ACF fields,
* post types, taxonomies and more in WP Admin.
*/
/**
* @link https://www.advancedcustomfields.com/resources/how-to-hide-acf-menu-from-clients/
*/
add_filter( 'acf/settings/show_admin', 'demo_acf_show_admin' );
<?php
/**
* This file adds functions to the child WordPress theme.
*/
/**
* Check for Notification Bar, and display it.
*/
function demo_acf_output_notification() {
$has_notice = get_field( 'notification_bar', 'options' );
name: Deploy to a WP Engine Development environment
on:
push:
branches:
- dev
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
@colorful-tones
colorful-tones / .gitignore
Last active April 28, 2024 20:05
An example .gitignore optimized for WP Engine hosting
#----------------------------------------
# This Git ignore should be located
# in your WordPress install's wp-content/
# directory.
#----------------------------------------
#---------------------------
# WordPress general
#---------------------------
/index.php
function qorp_about_block_template_lookup( $template, $type, array $templates ) {
if ( $template && 'page-about.php' === $templates[0] ) {
add_filter( 'the_content', 'qorp_append_post_meta_output' );
}
}
add_filter( 'page_template', 'qorp_about_block_template_lookup', 20, 3 );
function qorp_append_post_meta_output( $content ) {
ob_start();
<!-- wp:template-part {"slug":"header","tagName":"header","className":"site-header"} /-->
<!-- wp:group {"tagName":"main","className":"site-content","style":{"spacing":{"margin":{"top":"0"}}}} -->
<main class="wp-block-group site-content" style="margin-top:0">
<!-- wp:pattern {"slug":"frost/page-home"} /-->
</main>
<!-- /wp:group -->
<!-- wp:template-part {"slug":"footer","tagName":"footer","className":"site-footer"} /-->