Skip to content

Instantly share code, notes, and snippets.

@zackpyle
zackpyle / remove-custom-taxonomy-metaboxes.php
Last active May 18, 2023 13:37
Remove All Custom Taxonomy Sidebar Metaboxes #cptui #wordpress
<?php // ignore - for formatting only
// Useful if you are creating custom taxonomines and controlling them with ACF. This will remove all the metaboxes for your custom taxonomies
function edit_taxonomy_args( $args, $tax_slug, $cptui_tax_args ) {
// Set to false for all taxonomies created with CPTUI.
$args['meta_box_cb'] = false;
return $args;
}
add_filter( 'cptui_pre_register_taxonomy', 'edit_taxonomy_args', 10, 3 );
@zackpyle
zackpyle / default-image-acf.php
Last active May 18, 2023 13:37
Add default image setting to ACF image fields #acf
<?php //ignore this line - for formatting only
// 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 / custom date filter for events CPT in BB grid.php
Last active May 18, 2023 13:41
Custom Date Filter for Events CPT in BB Post Grid #beaverbuilder #acf
<?php //ignore - only for formatting
//Show Only Current and Future Events
function event_CPT_date_filter( $query_args ) {
if ( 'date-grid' == $query_args['settings']->id ) { //id of your module - example here is date-grid
$today = current_time('Ymd');
$type = 'events'; //CPT slug
$eventdate = 'event_end_date'; //ACF date picker field
@zackpyle
zackpyle / Move Old Event to Past Event Taxonomy.php
Last active May 18, 2023 13:41
Move Old Events to 'Past Event' Taxonomy #wordpress #cron
<?php //for formatting - ignore this line
// Move Old Events to 'Past Event' Taxonomy
add_action( 'hide_old_events', 'run_hide_old_events' );
add_action('admin_init', function() { // check on admin load, could be on init, but seems overkill
if (! wp_next_scheduled ( 'hide_old_events' )) { //see if the event is set
wp_schedule_event( strtotime('tomorrow 12:01am'), 'daily', 'hide_old_events' ); //Schedule it to run at 12:01 am - adjust to your liking
}
@zackpyle
zackpyle / _Beaver-Themer-ACF-Hero.md
Last active May 18, 2023 13:56
Beaver Themer + ACF - Hero Section #beaverbuilder #beaverthemer

This is a download to make a Hero section on your pages using Beaver Themer and ACF.

- Steps to install -

  1. Download this whole Gist as a zip and extract
  2. Import the Hero Field Group (acf-hero-fields.json) into ACF (/wp-admin/edit.php?post_type=acf-field-group&page=acf-tools) - I like to exclude my Homepage for this fieldgroup as my homepage always has a custom hero section
  3. Paste the function for adding the body class (hero-bg-body-class.php) into your functions.php file or snippet plugin, leaving out the <?php at the beginning of the file
  4. Paste the hero styles CSS (hero-styles.css) into wherever you are writing your CSS (styles.css, customizer, BB Global CSS, etc)
  5. Use Wordpress importer (/wp-admin/import.php) to import the Themer Part (hero-themer-part.xml). Same as the ACF field group, I like to exclude my Homepage from this Themer Part as it always gets a custom hero
  6. Open the Themer Part with BB and edit the Row settings. For the Background Photo section, click on the wrench to set
@zackpyle
zackpyle / Beaver-Builder-Themer-Ignores-WP-Custom-Permalink.php
Last active May 18, 2023 13:57
Beaver Builder and Beaver Themer ignore WP custom permalink by setting with_front to false #beaverbuilder #beaverthemer
@zackpyle
zackpyle / scrolled-header-code.js
Last active May 18, 2023 14:41
Swap Headers on Scroll in Beaver Builder/Beaver Themer #beaverbuilder #beaverthemer
/* JS for scrolled header: */
const header_a = document.querySelector('#header-row-a');
const header_b = document.querySelector('#header-row-b');
var posY = 0;
window.addEventListener('scroll', function(e) {
//how far down you scroll
if (this.pageYOffset > 855) {
if (this.pageYOffset > posY) {
@zackpyle
zackpyle / remove-custom-taxonomy-metabox.php
Last active May 18, 2023 14:42
Remove Custom Taxonomy Metabox from WP Sidebar #wordpress #cptui
<?php
// example custom post type is "event"
// example custom taxonomy is "events-category"
function remove_default_event_category_metabox() {
remove_meta_box( 'tagsdiv-events-category', 'event', 'side' );
}
add_action( 'admin_menu' , 'remove_default_event_category_metabox' );
@zackpyle
zackpyle / beaver-builder-noloop-vimeo-jQuery.js
Last active May 18, 2023 14:42
Turn Off Looping of Beaver Builder Background Vimeo Video #beaverbuilder
jQuery(document).ready(function($) {
let $vimeoPlayer = $('#hero-row .fl-bg-video').data('VMPlayer');
$vimeoPlayer.setLoop(false);
});
@zackpyle
zackpyle / acf-google-address-shortcode.php
Last active May 18, 2023 14:44
ACF Google Address Field Shortcode #acf
<?php
// ACF Google Map Field -> Address Shortcode
add_shortcode( 'acf_address' , function( $atts ) {
if (!function_exists('get_field') ) return '';
$atts = shortcode_atts( array( 'field' => false , 'sub' => 'address' ) , $atts, $shortcode = 'acf_address' );
if ($atts[ 'field' ] && $map = get_field( $atts[ 'field'] ) ) {
if ( isset( $map[ $atts['sub'] ] ) ) return $map[ $atts['sub'] ];
}
return '[ something went wrong ]';