Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / Remove Fluent Forms Multiselect Placeholder After Selecting.js
Last active October 12, 2023 20:49
Remove placeholder from Fluent Forms multiselect after selecting an item #fluentforms
jQuery(document).ready(function ($) {
$(".ff_has_multi_select").on("change", function (e) {
var selectedItem = $(this).siblings("input.choices__input");
selectedItem.attr("data-placeholder", selectedItem.attr("placeholder"));
if (e.target.options.length > 0) {
selectedItem.removeAttr("placeholder");
} else {
selectedItem.attr("placeholder", selectedItem.attr("data-placeholder"));
@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 / External Press Posts Redirect.php
Last active June 6, 2023 19:20
Conditionally redirect 'press' post type to external link if set #wordpress #acf #yoast
<?php //ignore - only for formatting
// Conditionally redirect 'press' post type to external link if set
// CPT = press
// Custom field -> point_this_content_to = (select field with 'internal' and 'external' as options)
// Custom field -> external_link = conditially displayed if point_this_content_to is set to 'external'
function redirect_external_link() {
@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 / 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 / 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 / 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
});