Skip to content

Instantly share code, notes, and snippets.

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

mark l chaves marklchaves

🏄‍♂️
View GitHub Profile
@marklchaves
marklchaves / nyt-style-wp-blocks-pattern.html
Created January 26, 2024 04:26
Example Content for New York Times Style Teaser
<!-- wp:columns -->
<div class="wp-block-columns"><!-- wp:column {"width":"30%"} -->
<div class="wp-block-column" style="flex-basis:30%"></div>
<!-- /wp:column -->
<!-- wp:column {"width":"40%"} -->
<div class="wp-block-column" style="flex-basis:40%"><!-- wp:group {"metadata":{"name":"Card"},"style":{"spacing":{"blockGap":"var:preset|spacing|small","padding":{"top":"var:preset|spacing|small","right":"var:preset|spacing|small","bottom":"var:preset|spacing|small","left":"var:preset|spacing|small"}},"border":{"radius":"5px"},"layout":{"selfStretch":"fixed","flexSize":"360px"}},"backgroundColor":"base","layout":{"type":"constrained"}} -->
<div class="wp-block-group has-base-background-color has-background" style="border-radius:5px;padding-top:var(--wp--preset--spacing--small);padding-right:var(--wp--preset--spacing--small);padding-bottom:var(--wp--preset--spacing--small);padding-left:var(--wp--preset--spacing--small)"><!-- wp:group {"style":{"spacing":{"blockGap":"var:preset|spacing|small"}},"layout":{"type":"co
@marklchaves
marklchaves / popup-maker-disable-if-elementor-live-preview.php
Last active January 23, 2024 16:43
Disable Popup Maker if Elementor Preview Mode is Active
<?php // Ignore this first line when copying to your child theme's functions.php file.
/**
* Disable Popup Maker if Elementor Preview Mode is Active
*
* References:
* - https://code.elementor.com/methods/elementor-preview-is_preview_mode/
* - https://ralphjsmit.com/elementor-check-active/
*/
@marklchaves
marklchaves / listen_for_alternate_close.php
Last active June 14, 2023 14:03
Popup Maker: A workaround to fix the alternate close methods not working on back-to-back popups.
<?php // Ignore this first line when copying to your child theme's functions.php file.
/**
* Listen for alternate close
*
* A workaround to fix the alternate close methods not working on back-to-back popups.
*
*/
function listen_for_alternate_close() { ?>
<script type="text/javascript">
@marklchaves
marklchaves / every_third_page.php
Last active June 14, 2023 05:05
Show a popup on every third page
<?php // Ignore this first line when copying to your child theme's functions.php file.
function every_third_page() { ?>
<script type="text/javascript">
/** Set up a page counter in the browser's session storage. */
(function(){
let pc = parseInt(sessionStorage.getItem("my-page-count"));
if (!pc) {
sessionStorage.setItem("my-page-count", 1);
@marklchaves
marklchaves / say_hello_sc.php
Last active June 6, 2023 04:02
The say hello shortcode prints your display name and role if you're logged into a WordPress site. This is great if you need to know who you are logged in as and what role you have for any given post/page you're on.
<?php // Ignore this first line when copying to your child theme's functions.php file.
function say_hello_sc() {
$u = wp_get_current_user();
$display_name = $u->display_name ?: 'there';
$roles = (array) $u->roles ?: ['not logged in'];
return '<p>Yo, <strong>' . $display_name . '</strong> (<em>' . $roles[0] . '</em>)' . '. Thanks for stopping by ;-)</p>';
}
add_shortcode('say_hello', 'say_hello_sc');
/**
@marklchaves
marklchaves / holy_smokes_function.php
Last active May 31, 2023 04:03
Popup Maker: Use a filter or shortcode to display a popup's contents including its ACF
<?php // Ignore this first line when copying to your child theme's functions.php file.
/** Use a Popup Maker filter to tack on the popup's ACF if it has one. */
function holy_smokes_function($content, $id)
{
$acf_value = get_post_meta($id, 'test', true);
return $content . '<p>Holy smokes, Batman! ' . ($acf_value ? $acf_value : 'Aw, nothing :-(') . '</p>';
}
add_filter('pum_popup_content', 'holy_smokes_function', $content, $id);
@marklchaves
marklchaves / custom_url_contains_condition.php
Last active May 15, 2023 00:01
Popup Maker Custom Trigger PHP Function for Loading a Popup Based URL contains using the ATC extension
<?php // Ignore this first line when copying to your child theme's functions.php file.
/**
* This PHP function will load a popup on a post or page only if the URL
* contains the string "yourstringgoeshere" in it.
*
* Usage:
* 1) Install the code snippet below. Make sure you change "yourstringgoeshere" to the string that'll
* be in your URL that you want to launch the popup. Example: https://twenty-twentyone.test/yourstringgoeshere/
* 2) Install the Popup Maker Advanced Targeting Conditions extension.
@marklchaves
marklchaves / add-missing-form-ids-avada.js
Created May 27, 2021 23:56
Try to add missing form IDs to Avada Forms to help with conversion tracking.
/**
* Try to add missing form IDs to Avada Forms
* to help with conversion tracking.
*/
(function(){
// Grab all the forms on the page.
const formElts = document.querySelectorAll("form");
// If no forms, bail.
if (!formElts.length) return;
@marklchaves
marklchaves / rc_ajax_demo_js.php
Last active April 24, 2023 09:14
Popup Maker Remote Content AJAX Example Passing in a Shortcode Name
<?php // Ignore this first line when copying to your child theme's functions.php file.
/**
* Based on the doc "Remote Content -- AJAX Type Introduction"
*
* https://docs.wppopupmaker.com/article/33-remote-content-ajax-type-introduction
*
* What's the difference?
*
* The 'name' arg is the name of a shortcode. In this example, the
@marklchaves
marklchaves / avada-theme-header-footer-hooks-README.md
Last active April 10, 2023 16:04
Avada Header and Footer Hooks