Skip to content

Instantly share code, notes, and snippets.

View marklchaves's full-sized avatar
🏄‍♂️

mark l chaves marklchaves

🏄‍♂️
View GitHub Profile
@marklchaves
marklchaves / send_video_link_to_popup_data_attribute.php
Last active March 3, 2025 09:35
Open a popup that dynamically loads a video based on the click open trigger using 1) data attribute or 2) a query parameter
@marklchaves
marklchaves / replace_compliments_button.php
Last active June 23, 2022 22:58
Replace an HTML element if logged in as a subscriber
<?php // Ignore this first line when copying to your child theme's functions.php file.
add_filter( 'wp_footer', function() {
if ( !is_user_logged_in() ) return; // Don't do anything if not logged in.
global $current_user;
$user_roles = $current_user->roles;
// var_dump($user_roles); // Uncomment to debug role(s).
$user_role = array_shift( $user_roles ); // Look at the first role. Change this if needed.
if ( $user_role !== "subscriber") return; // Bail early if we don't have a subscriber.
@marklchaves
marklchaves / display_random_banner_popups.php
Last active June 15, 2022 12:49
Randomly Display Banner Popups or Display Banner Popups for A/B (Split) Testing
<?php // Ignore this first line when copying to your child theme's functions.php file.
function display_random_banner_popups() { ?>
<script type="text/javascript">
jQuery(document).ready(function ($) {
// Customize these variables.
// ----------------------------------
const popups = [1100, 1102, 1104], // Comma separated popup IDs.
cookieName = "pum-split-test", // Cookie name for the A/B test only.
cookieTime = "1 minute"; // Cookie timer.
// ------------------------------
@marklchaves
marklchaves / send_link_to_popup.php
Last active June 9, 2022 08:42
Send a link to a popup and use that link in the popup as a button
@marklchaves
marklchaves / launch_a_popup_if_cookie_consent_accepted.php
Created June 7, 2022 04:50
Launch a popup after cookie consent accepted
@marklchaves
marklchaves / html-source-example-click-open-link.html
Last active February 17, 2025 12:49
Send a query parameter to a form inside a Popup Maker popup
@marklchaves
marklchaves / find-all-forms-and-missing-ids.js
Created June 1, 2022 02:44
Find all forms and flag forms with no IDs
let firstNoId = true;
let forms = [];
let noIds = [];
let out = "";
/** Place a border around forms with no ID set. */
document.querySelectorAll("form").forEach((f) => {
if (!f.hasAttribute("id")) {
if (firstNoId) {
firstNoId = false;
@marklchaves
marklchaves / force_signature_width.php
Last active June 1, 2022 02:00
Force Gravity Forms Signature Field Width
<?php // Ignore this first line when copying to your child theme's functions.php file.
add_action( 'wp_footer', function() { ?>
<script type="text/javascript">
// Convenience function to wrap multiple functions with timeouts.
function createFunctionWithTimeout(callback, optTimeout) {
let called = false;
function fn() {
if (!called) {
@marklchaves
marklchaves / add_js_cookie_enqueue_script.php
Last active May 27, 2022 01:40
Use the js-cookie API to set a cookie when download page loads
@marklchaves
marklchaves / only_one_mobile_submenu_at_a_time.php
Last active March 25, 2022 12:47
Open One Avada Mobile Submenu Item at a Time
<?php // Ignore this first line when copying to your child theme's functions.php file.
function only_one_mobile_submenu_at_a_time() { ?>
<script type="text/javascript">
jQuery(document).ready(function ($) {
$( 'button.fusion-open-submenu' ).on( 'click', function() {
$( 'button.fusion-open-submenu' ).not( $( this ) ).removeClass( 'chevron--up' );
$( this ).toggleClass( 'chevron--up' );
$( this ).parent( 'li.menu-item-has-children' ).siblings().find( '.sub-menu' ).removeClass( 'fusion-sub-menu-open' ).attr( 'style', 'display: none;' );
} ); // Click