Skip to content

Instantly share code, notes, and snippets.

@zackpyle
zackpyle / beaver-map-module-zoom.php
Last active May 18, 2023 13:36
Set zoom level on Beaver Builder Map module #beaverbuilder
<?php // ignore - for github formatting purposes
add_filter( 'fl_builder_map_args', function( $args, $settings ) {
$args['zoom'] = 18;
return $args;
}, 10, 2 );
@zackpyle
zackpyle / Add-Page-Slug-to-Body-Class.php
Last active May 18, 2023 13:36
Page Slug Body Class #wordpress
<?php // ignore - for gist formatting only
// Add Page Slug to Body Class
function add_slug_body_class( $classes ) {
global $post;
if ( isset( $post ) ) {
$classes[] = $post->post_type . '-' . $post->post_name;
}
return $classes;
}
@zackpyle
zackpyle / _Dynamic dropdown + content pulled from CPT.md
Last active May 18, 2023 13:36
Dynamic content using a <select> dropdown on the frontend, and pulls content from a CPT. Output content using L&L #loopsandlogic #l&l

Pull posts from a CPT into a <select> field and then display content from that post based on if it is selected

- This example is showing a list of insurance companies and which states they cover

  1. The content is pulled from a CPT called insurance_company. That CPT has a taxonomy called state. Using Loops & Logic, we will output a <select> containing the insurance companies.
  2. Next to that, we will output a list of divs, one for each insurance company with their corresponding covered States.
  3. Then with the JS, we will hide all those divs, leaving an instructional div showing when nothing is selected. When an insurance company is selected, we will find the matching div and display it.
@zackpyle
zackpyle / posts-by-category.html
Last active May 18, 2023 13:35
Output posts separated by category using Loops & Logic plugin - Example using a Team and Team Category #loopsandlogic #l&l
<!-- Team CPT (team_member), and Team Category (team_category) - Separeted into their categories -->
<!-- Note: In this case, the order of the taxonomy matters, so we will use a plugin to set
menu order of team_category and use orderby=menu_order to respect that order instead of just outputting it in alpha order -->
<Loop type=taxonomy_term taxonomy=team_category orderby=menu_order>
<h2><Field title /></h2>
<Loop type=team_member taxonomy=team_category terms="{Field id}">
<Field title />
@zackpyle
zackpyle / equal-heights-by-row.js
Last active October 17, 2023 18:45
Set separate equal heights for each row of content on the page. This eliminates large gaps in content further down caused by a single tall item but keeps the items in the row equal with each other.
// Add this to your indivdual pages
jQuery(document).ready(function ($) {
setEqualHeights('.myClass');
});
// And then add this to your global js
jQuery(document).ready(function ($) {
$.fn.equalHeights = function() {
var max_height = 0;
@zackpyle
zackpyle / scroll-down-button.js
Created March 28, 2023 13:45
A Button that scrolls the page down from section to section smoothly
// A Button that scrolls the page down from section to section smoothly
// Button needs to be positioned absolutely and design using css or a builder
// Here is the demo of this button in use https://youtu.be/_JZ9k0kT7yY?t=382
// Borrowed from https://github.com/thisbit/github_snippets/blob/main/js/scroll-down-button.js and converted to jQuery
jQuery(document).ready(function($) {
const $button = $('.carret-down');
const $sections = $('.custom-section');
function* goToNextSection(event) {
@zackpyle
zackpyle / current-user-posts.php
Last active May 18, 2023 13:34
Only show current user's posts in BB post module #beaverbuilder
<?php //ignore - only for gist formatting
// Only show current user's posts in BB post module with current-user as module ID
function showAuthorPosts( $query_args ) {
if ( 'current-user' == $query_args['settings']->id ) { // Set the id of the post module to current-user
$query_args['author'] = get_current_user_id(); // Filter by the current logged-in user
}
return $query_args;
}
add_filter( 'fl_builder_loop_query_args', 'showAuthorPosts' );
@zackpyle
zackpyle / fluentform-submission-success.js
Last active April 19, 2024 10:06 — forked from techjewel/fluentform-submission-success.js
Form submission success JS Event in Fluent Forms #fluentforms
// Event on form submission success
// You can paste this script to Form's custom JS Box
$form.on('fluentform_submission_success', function() {
document.cookie = 'cookieName=1; max-age='+90*24*60*60+'; path=/'; // Set cookie on form submission
});
@zackpyle
zackpyle / URL-Param-Shortcode.php
Created May 16, 2023 12:56
Use the [URLParam param='paramName'] shortcode to display GET parameters from the current URL
<?php // ignore this line - only for formatting
// Use the [URLParam param='paramName'] shortcode to display GET parameters from the current URL
function displayURLparam( $atts ) {
extract( shortcode_atts( array(
'param' => 'param',
), $atts ) );
return esc_attr(esc_html($_GET[$param]));
}
@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();
}
});