Skip to content

Instantly share code, notes, and snippets.

View addisonhall's full-sized avatar

Addison Hall addisonhall

View GitHub Profile
@addisonhall
addisonhall / add-template-tag.php
Last active June 9, 2025 14:34
Big dropdown snippets for use with GeneratePress and GenerateBlocks, uses GP Elements
<?php
/**
* Add custom HTML tag(s) to GenerateBlocks Loop Item
* @link https://generate.support/topic/gb-headline-dynamic-data-open-in-new-tab-not-workin/#post-165999
*/
add_filter('block_type_metadata', function($metadata) {
if (isset($metadata['name']) && $metadata['name'] === 'generateblocks/element') {
$metadata['attributes']['tagName']['enum'] = array_merge(
$metadata['attributes']['tagName']['enum'],
@addisonhall
addisonhall / gallery-block-lightbox-customizations.php
Last active May 30, 2025 15:08
"Lightbox for Gallery & Image Block" customizations for ACF/GenerateBlocks setup
@addisonhall
addisonhall / block.php
Created May 23, 2025 14:53
block.php for custom blocks where a post object field selects post for output. Custom hook name for use with GenerateBlocks elements.
<?php
/**
* ACF Block PHP for custom blocks where a post object field selects post for output.
* Custom hook name for use with GenerateBlocks elements.
*
* @link https://www.advancedcustomfields.com/resources/create-your-first-acf-block/
* @see https://youtu.be/TZsVq-jd0Ao
*/
// don't access this file directly!
@addisonhall
addisonhall / wp-content-security-policy.php
Last active March 19, 2025 18:29
WordPress Content Security Policy (I use with GeneratePress theme)
<?php
/**
* Content security policy with nonces. Doesn't work great with caching.
*
* Do some security stuff to harden WordPress.
* Must be included in functions.php
*
* @package GenerateChild
* @see https://content-security-policy.com/ Reference guide for content security policies
* @see https://csp-evaluator.withgoogle.com/ Test with Google's CSP Evaluator
@addisonhall
addisonhall / ahd-parse-query-string-wp-shortcode.php
Last active March 7, 2025 15:06
WordPress shortcode to parse URL query string parameters. Drop into functions.php and add to a custom plugin.
<?php
/**
* Parse query string parameters.
* @example [ahd_parse_query_string param="parameter_name"]
*/
function ahd_parse_query_string_func( $atts ) {
// get shortcode attributes
$atts = shortcode_atts( array(
'param' => '',
@addisonhall
addisonhall / acf-resource-block-and-cpt-and-categories.json
Last active January 30, 2025 19:58
ACF Resource Block, Custom Post Type, and Categories
[
{
"key": "group_675735fb4fdc1",
"title": "Resources Block",
"fields": [
{
"key": "field_675735fb56013",
"label": "Resources Block",
"name": "",
"aria-label": "",
@addisonhall
addisonhall / Page-before-body-closing.html
Last active October 10, 2023 22:07
Webflow Hero Slider using Swiper JS
<script>
/**
* Activate swiper.js for testimonials
*/
doHeroSlider();
function doHeroSlider() {
// get hero slider element
const heroSlider = document.getElementById('heroSlider');
// shut it down if slider isn't present
@addisonhall
addisonhall / ACF_random_image.php
Last active November 22, 2021 21:22
ACF random image for GeneratePress background image URL
<?php
add_filter( 'generate_page_hero_background_image_url', function( $url ) {
$headers = array(
esc_url(get_field('radnomizer_image_one')),
esc_url(get_field('radnomizer_image_two')),
esc_url(get_field('radnomizer_image_three')),
esc_url(get_field('radnomizer_image_four')),
esc_url(get_field('radnomizer_image_five'))
);
@addisonhall
addisonhall / get_post_title_shortcode.php
Created September 6, 2021 18:05
Simple Wordpress shortcode to output current post title
/**
* Output the post title.
* [gpc_post_title]
*/
add_shortcode( 'gpc_post_title', 'gpc_post_title_func' );
function gpc_post_title_func() {
return get_the_title();
}
@addisonhall
addisonhall / gp-hide-paging-navigation.css
Last active November 12, 2020 19:23
Hide GeneratePress post navigation via CSS
.paging-navigation {
display: none;
}