Skip to content

Instantly share code, notes, and snippets.

@bacoords
bacoords / .gitignore
Last active January 20, 2023 05:25
Default WordPress/WP Engine .gitignore File
# Wordpress - ignore core, configuration, examples, uploads and logs.
# Forked from: https://github.com/github/gitignore/blob/main/WordPress.gitignore
# Core
/wp-admin/
/wp-content/index.php
/wp-content/languages
/wp-content/plugins/index.php
/wp-content/themes/index.php
/wp-content/uploads/
@bacoords
bacoords / readme.md
Created November 29, 2022 15:21
Default WordPress Readme File

Project Name

This is the public folder for Project Name. It can be used for your local development and is also used to push code to the staging and live environments via WP Engine's Git Push.

It currently contains the source code for:

@bacoords
bacoords / editor.js
Created March 9, 2023 01:14
Remove core blocks from WordPress block editor
wp.domReady( () => {
let blocks = wp.blocks.getBlockTypes().map( ( block ) => block.name );
blocks.forEach( ( block ) => {
if ( block.indexOf( 'core/' ) === 0 ) {
wp.blocks.unregisterBlockType( block );
}
});
} );
@bacoords
bacoords / render.php
Last active March 15, 2023 04:56
PHP header for a dynamic gutenberg blocks render.php file
<?php
/**
* All of the parameters passed to the function where this file is being required are accessible in this scope:
*
* @param array $attributes The array of attributes for this block.
* @param string $content Rendered block output. ie. <InnerBlocks.Content />.
* @param WP_Block $block The instance of the WP_Block class that represents the block being rendered.
*
* @package gutenberg-examples
*/
import { useSelect } from '@wordpress/data';
/**
* AttachmentImage
*
* This component is used to display an image from the media library.
* It's meant as a JS companion to the PHP function `wp_get_attachment_image()`.
*
* @link https://www.briancoords.com/getting-wordpress-media-library-images-in-javascript/
<?php
function my_body_classes( $classes ){
if ( is_page( 'about' ) ) {
$classes[] = 'page-about';
}
return $classes;
}
@bacoords
bacoords / block-pattern-preview.php
Last active June 1, 2024 11:25
Preview your block patterns on the frontend of your website
<?php
/**
* Plugin Name: Block Pattern Preview
* Description: Allows you to preview block patterns on the frontend of your website.
* Author: Brian Coords
* Author URI: https://www.briancoords.com
* Version: 0.0.1
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
*
@bacoords
bacoords / acf-json-import.php
Created May 16, 2023 05:32
Import exported ACF Field Groups on plugin activation
<?php
/**
* Helper function to import the ACF field group if it doesn't exist.
*
* @return void
*/
function example_import_acf_field_group() {
if ( function_exists( 'acf_import_field_group' ) ) {
// Get all json files from the /acf-field-groups directory in your plugin.
@bacoords
bacoords / render.php
Created June 21, 2023 20:14
ACF Block Render Starter
<?php
/**
* ACF Block Template.
*
* @param array $block The block settings and attributes.
* @param string $content The block inner HTML (empty).
* @param bool $is_preview True during backend preview render.
* @param int $post_id The post ID the block is rendering content against.
* This is either the post ID currently being displayed inside a query loop,
* or the post ID of the post hosting this block.
@bacoords
bacoords / twitter-font-awesome-4.css
Last active April 10, 2025 13:35
Update the Twitter / X Icon in Font Awesome 4
.fa.fa-twitter{
font-family:sans-serif;
}
.fa.fa-twitter::before{
content:"𝕏";
font-size:1.2em;
}