Skip to content

Instantly share code, notes, and snippets.

@zackpyle
zackpyle / ACF default image setting.php
Created November 28, 2023 20:05
Adds a default image option to ACF image fields using the built in default value #ACF functionality
<?php //ignore - for gist formatting
// add default image setting to acf image field
add_action('acf/render_field_settings/type=image', 'add_default_value_to_image_field');
function add_default_value_to_image_field($field) {
acf_render_field_setting( $field, array(
'label' => 'Default Image',
'instructions' => 'Appears when creating a new post',
'type' => 'image',
'name' => 'default_value',
@zackpyle
zackpyle / convert24hr-am-pm.js
Created October 3, 2023 15:01
Convert 24 hour time to AM/PM
// Convert 24 hr times (ex: 11:00:00 - 16:00:00) to AM/PM (11:00am - 4:00pm)
jQuery(document).ready(function ($) {
$('.event-time').each(function() {
const timeRange = $(this).text().split(' - ');
const startTime = convertToAMPM(timeRange[0]);
const endTime = convertToAMPM(timeRange[1]);
const formattedTime = `${startTime} - ${endTime}`;
$(this).text(formattedTime);
});
@zackpyle
zackpyle / BB query - Tax term + additional separate tax term.php
Created September 12, 2023 15:39
Custom query for Beaver Builder to combine current taxonomy term archive query + additional separate tax term
<?php // ignore this line - for gist formatting purposes
function fl_builder_loop_query_args_filter( $query_args ) {
global $wp_query;
if ( 'topic-featured-posts' == $query_args['settings']->id ) { // BB Module ID
// Get the current term object
$current_term = get_queried_object();
@zackpyle
zackpyle / *SEOPress Primary Category Shortcode.php
Last active January 9, 2024 17:17
Use [primary_category] to display SEOPress Primary Category
<?php //ignore this line - for gist formatting
function get_primary_category_name() {
// Get the post ID of the current page
$post_id = get_the_ID();
$cat_id = get_post_meta($post_id, '_seopress_robots_primary_cat', true);
// Validate and get the category name
if (!empty($cat_id)) {
$term = get_term($cat_id, 'category');

Two options to format US phone numbers

Loops and Logic
Use Loops and Logic's regex feature using capture groups to grab the parts, then insert . or - when reassembling the capture groups

Javascript
Using JS to extract (slice) the phone number into separete parts, inject the . or - and reassemble

@zackpyle
zackpyle / fluid-typography.css
Last active November 16, 2023 09:42
Fluid Typography
:root {
--ff-heading: 'Playfair Display', serif;
--ff-text: 'Source Sans Pro', sans-serif;
--fs-h1: clamp(40px, 6.0vw + 10px, 85px);
--fs-h2: clamp(30px, 1.7vw + 23px, 45px);
--fs-h3: clamp(25px, 1.3vw + 18px, 35px);
--fs-h4: clamp(20px, 1vw + 15px, 28px);
--fs-h5: clamp(16px, 0.9vw + 12px, 22px);
@zackpyle
zackpyle / *Custom gallery and Magnific Popup.md
Last active July 27, 2023 01:07
Create a custom gallery layout + lightbox functionality including next / prev navigation buttons
@zackpyle
zackpyle / post-author-delete-shortcode.php
Last active June 2, 2023 16:33
Make a shortcode [delete-post] for users to delete a post from the frontend if they are the author of that post
<?php //ignore this line - for git formatting
function delete_post_shortcode($atts) {
$post_id = get_the_ID();
// Check if the user is logged in and is the author of the post
if (is_user_logged_in() && is_singular() && get_the_author_meta('ID') === get_current_user_id()) {
ob_start();
?>
<button type="button" id="delete-post-button">Delete</button>
@zackpyle
zackpyle / *Add WP user role to body class.md
Last active May 19, 2023 14:16
Add WP user role as body class #wordpress

Take the current user's wordpress role, and add it to the body class as role-[users role]

@zackpyle
zackpyle / Add Page Slug to Body Class.php
Created May 18, 2023 18:37
Adds page slub to the body class prepended by the post type name
<?php // ignore this line - only for styling
function add_slug_body_class( $classes ) {
global $post;
if ( isset( $post ) ) {
$classes[] = $post->post_type . '-' . $post->post_name;
}
return $classes;
}
add_filter( 'body_class', 'add_slug_body_class' );