Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / bb-dropdown-custom-order.php
Created February 19, 2024 14:28
Create a custom order for the Beaver Builder admin bar dropdown #beaverbuilder
<?php
add_filter( 'fl_theme_builder_current_page_layouts', function( $layouts ) {
// Custom order
$custom_order = ['header', 'singular', 'archive', '404', 'part' , 'footer'];
$sorted_layouts = [];
// Populate sorted_layouts based on custom_order
foreach ($custom_order as $type) {
if (isset($layouts[$type])) {
@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;
@zackpyle
zackpyle / acf_relationship_1to1_shortcode.php
Created January 30, 2024 14:40
Shortcode to return values from a 1:1 ACF relationship
<?php
function acf_relationship_shortcode($atts) {
$atts = shortcode_atts(array(
'name' => '', // ACF field name for the relationship
'display' => '', // ACF field name or WordPress field to display from the related post
'size' => 'full' // OPTIONAL - Size of the featured image (defaults to 'full')
), $atts);
if (empty($atts['name']) || empty($atts['display'])) {
@zackpyle
zackpyle / Beaver Builder Row Slider - L&L Template.html
Last active January 14, 2024 20:07
Create a Beaver Builder row slider using L&L and Slick Slider
<div class="hero-slider">
<List saved_ids>
<Loop type=fl-builder-template taxonomy=fl-builder-template-category terms=home-hero-slider>
<Item><Field id /></Item>
</Loop>
</List>
<Loop list=saved_ids>
<div class="element">
<Shortcode fl_builder_insert_layout id="{Field}" type=fl-builder-template />
</div>
@zackpyle
zackpyle / _default acf taxonomy field.php
Last active February 14, 2024 20:12
Set a default taxonomy #ACF value
<?php // ignore - for gist formatting
// Specify your ACF field here
add_filter('acf/load_field/name=your_field_name', function ($field) {
global $pagenow;
// Set the default term ID
$default_value = 'XXX';
// Apply the default value only when creating a new post