Skip to content

Instantly share code, notes, and snippets.

@zackpyle
zackpyle / acf-repeater-hide-show-jquery.js
Last active May 18, 2023 14:45
ACF Repeater + Hide/Show jQuery #acf #beaverbuilder
jQuery(document).ready(function($) {
// Hide all expanded steps
$('.expandedstep').hide()
//Show expanded steps while in the builder
$('html.fl-builder-edit .expandedstep').show();
// When an expand step button is clicked
$('.expandstepbtn').on('click', function(e) {
@zackpyle
zackpyle / *Best PowerPack Module Customization Snippets*
Last active May 18, 2023 15:26
Best PowerPack Module Customization Snippets #powerpack #beaverbuilder
Collection of PowerPack module customizations I've gathered over the years
@zackpyle
zackpyle / _Auto-Play-Pause-Vimeo-Youtube-Bootstrap-modal.md
Last active May 18, 2023 15:45
Auto Play/Pause Vimeo/Youtube videos on Bootstrap modal open/close #bootstrap

Auto Play/Pause Vimeo/Youtube videos on Bootstrap modal open/close

If you are using Bootstrap modals and have Youtube or Vimeo videos inside of them, you can use js to auto play/pause the video when the modal is opened/closed.

There are three options below.

  1. Vimeo using the Player SDK to pause/play
  2. Youtube by removing/adding the src when closing and and adding &autoplay=1 when opening
  3. Youtube by using the YouTube Player API, but you have to add the video via js to control it with the API
@zackpyle
zackpyle / add-all-themer-categories-to-themer-layout.php
Last active May 18, 2023 16:07
Adds the assigned terms from 'fl-builder-template-category' to the Themer Layout as a 'data-category' attribute #beaverbuilder #beaverthemer
<?php //ignore - only for formatting
// Adds the all assigned terms from 'fl-builder-template-category' into 'data-category' attribute
// You can target what you need by using a wildcard selector like [data-category*="your_category"]
add_filter( 'fl_render_content_by_id_attrs', function( $attrs, $post_id ) {
$terms = wp_get_post_terms($post_id, 'fl-builder-template-category');
if (!is_wp_error($terms) && !empty($terms)) {
$term_slugs = array();
foreach ($terms as $term) {
@zackpyle
zackpyle / Allow SVGs to be uploaded in BB.php
Created May 18, 2023 18:15
Allow SVGs to be uploaded in Beaver Builder #beaverbuilder
<?php //ignore - only for formatting
add_filter( 'fl_module_upload_regex', function( $regex, $type, $ext, $file ) {
$regex['photo'] = '#(jpe?g|png|gif|bmp|tiff?|webp|svg)#i';
return $regex;
}, 10, 4 );
@zackpyle
zackpyle / hide-multiple-themer-parts-above-header.js
Last active May 18, 2023 18:21
Only show one Themer Part above the <header> at a time in case multiple are assigned to the same location #beaverbuilder #beaverthemer
jQuery(document).ready(function($) {
let themerPartsBeforeHeader = $('div[data-type="part"]').prevUntil('header');
// Show only the first Themer Part if there are two or more before the <header>
if (themerPartsBeforeHeader.length > 1) {
themerPartsBeforeHeader.slice(1).hide();
}
});
@zackpyle
zackpyle / custom-taxonomy-body-class.php
Created May 18, 2023 18:36
Add custom taxonomy to body class of singular post #wordpress
<?php // ignore this line - only for styling
function add_taxonomy_to_single( $classes ) {
if ( is_single() ) {
global $post;
$my_terms = get_the_terms( $post->ID, 'insert_taxonomy_slug' );
if ( $my_terms && ! is_wp_error( $my_terms ) ) {
$classes[] = $my_terms[0]->slug;
}
}
@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' );
@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 / *ACF Snippets.md
Last active May 19, 2023 14:31
Collection of useful ACF snippets #acf

Collection of useful ACF Snippets

  1. Add Field to Body Class
  2. Custom Excerpt Field
  3. Default Image
  4. Google Address Shortcode
  5. Google Map Multiple Marker Shortcode
  6. Numbers with commas
  7. Repeater + Bootstrap Modal + Modal Nav
  8. Repeater with button for Show-Hide