Skip to content

Instantly share code, notes, and snippets.

@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 / _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 / 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 / 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 / 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 / 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 / post-author-delete-shortcode.php
Last active June 2, 2023 16:33
Make a shortcode [delete-post] for users to delete a post from the frontend if they are the author of that post
<?php //ignore this line - for git formatting
function delete_post_shortcode($atts) {
$post_id = get_the_ID();
// Check if the user is logged in and is the author of the post
if (is_user_logged_in() && is_singular() && get_the_author_meta('ID') === get_current_user_id()) {
ob_start();
?>
<button type="button" id="delete-post-button">Delete</button>
@zackpyle
zackpyle / *Custom gallery and Magnific Popup.md
Last active May 18, 2024 12:23
Create a custom gallery layout + lightbox functionality including next / prev navigation buttons