Skip to content

Instantly share code, notes, and snippets.

@zackpyle
zackpyle / modify-bb-post-autosuggest-dropdown.php
Last active May 4, 2024 00:19
Add URL to Beaver Builder Post module auto suggest dropdown
<?php
// Modify the data returned for BB post module auto suggest queries to include post URLs
add_filter('fl_builder_auto_suggest_posts_lookup', function ( $data ) {
foreach ( $data as $key => $post ) {
$post_object = get_post( $post['value'] );
// If the post object exists, append the URL path to the title
if ( $post_object ) {
$permalink = get_permalink( $post['value'] );
@zackpyle
zackpyle / *Best Snippets*
Last active May 1, 2024 20:05
Best PHP/JS Snippets
This is a collection of my most used or most useful PHP and JS snippets
**Disclaimer, I didn't write most of these - I just curated them over the years**
@zackpyle
zackpyle / fluid-typography.css
Last active May 1, 2024 20:04
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 / fluent-forms-dynamic-submit-button-text.php
Last active April 24, 2024 21:42
Fluent Forms - Use custom shortcode attr and FF SmartCode to pass dynamic Submit Button text
<?php
// Register Fluent Forms SmartCode
add_filter('fluentform/editor_shortcodes', function ($smartCodes) {
$smartCodes[0]['shortcodes']['{submit_button_text}'] = 'Dynamic Submit Button Text';
return $smartCodes;
});
// Use text from submit_button_text attribute on the form's shortcode
add_filter('fluentform/editor_shortcode_callback_submit_button_text', function ($value, $form) {
@zackpyle
zackpyle / fluent-forms-post-type-checkbox.php
Last active April 24, 2024 16:25
In Fluent Forms, set the values of a checkbox to a post type's posts
<?php
add_filter('fluentform/rendering_field_data_input_checkbox', function ($data, $form) {
if ($form->id != 1) { // Form ID
return $data;
}
// Set which field to do this on
if (\FluentForm\Framework\Helpers\ArrayHelper::get($data, 'attributes.name') != 'products') { // Field name
return $data;
@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 / beaver-themer-location-singular-class.php
Created April 7, 2024 18:22
Add Beaver Themer's location setting for Singular template as a body class of single-post_type to help with styling the Themer Layout
<?php
add_filter('body_class', function ($classes) {
if (is_singular('fl-theme-layout')) {
$current_post_id = get_the_ID();
$layout_type = get_post_meta($current_post_id, '_fl_theme_layout_type', true);
$location_settings = get_post_meta($current_post_id, '_fl_theme_builder_locations', true);
// Proceed only if the layout type is 'singular'
if ($layout_type === 'singular' && !empty($location_settings) && is_array($location_settings)) {
@zackpyle
zackpyle / pp-generic-slider.css
Last active March 21, 2024 17:39
This is definitely not the best way to do this, but I modified the Powerpack Testimonial Slider to be a generic slider using js and css. I wouldn't recommend doing this haha
/*Turn Testimonials Module into Generic Slider*/
.fl-builder-pp-testimonials-settings h1,
.fl-builder-pp-testimonials-settings .fl-builder-settings-tabs a:nth-child(2),
.fl-builder-pp-testimonials-settings .fl-builder-settings-tabs a:nth-child(3),
.fl-builder-pp-testimonials-settings #fl-builder-settings-section-heading_fonts,
.fl-builder-pp-testimonials-settings #fl-builder-settings-section-subtitle_fonts{
display: none;
}
.slider-module.fl-builder-pp-testimonials-settings h1{
display: block;
@zackpyle
zackpyle / default-acf-value-by-post-type.php
Last active March 8, 2024 16:40
Set a different default #ACF value based on the post type
<?php
add_filter('acf/load_field/key=YOUR_FIELD_KEY_HERE', function ($field) {
if (get_post_type() == 'post') {
$field['default_value'] = 'YOUR_DEFAULT_VALUE_HERE';
}
return $field;
});
@zackpyle
zackpyle / Improved Dragging BB Nodes.css
Last active March 6, 2024 21:31
BB CSS for improved node dragging
/* Improved Dragging BB Nodes */
.fl-lightbox{
transition: all .2s ease-in-out;
}
.fl-builder-dragging .fl-lightbox{
opacity: .25;
}
.fl-builder-block-drag-helper.ui-sortable-helper {
margin-top: 40px;
margin-left: 20px;