Skip to content

Instantly share code, notes, and snippets.

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

mark marklchaves

🏄‍♂️
View GitHub Profile
@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 / my_first_name_sc.php
Last active September 15, 2025 12:54
Popup Maker Remote Content AJAX Example Running a Shortcode to Dynamically Generate Popup Content
<?php // Ignore this first line when copying to your child theme's functions.php file.
/**
* Add the my_first_name shortcode.
*/
function my_first_name_sc() {
$u = wp_get_current_user();
// Default to the display name if there's no first name. Default to 'there' if the person is not logged in.
$fname = $u->first_name ?: ($u->display_name ?: 'there');
return $fname;
@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 / popup_maker_generateblocks_do_content.php
Created April 3, 2023 12:22
Tell GenerateBlocks about Popup Maker's custom post type so GenerateBlocks can scan the popup content and spit out the dynamic CSS it needs
<?php // Ignore this first line when copying to your child theme's functions.php file.
/*
* This solution should be the accepted answer in this forum thread.
*
* https://generatepress.com/forums/topic/gpgbpopup-maker-issue/#post-2088153
*/
add_filter( 'generateblocks_do_content', function( $content ) {
$post_id = 467; // Change to your Popup Maker popup ID https://docs.wppopupmaker.com/article/409-find-the-popup-id
@marklchaves
marklchaves / landing-page-template.php
Created March 10, 2023 00:32
This template will display only the content you entered in the page editor. It'll still load header and footer scripts but not header, sidebar, and footer content.
<?php
/**
* Template Name: Landing Page Template
*
* This template will display only the content you entered in the page editor.
*
* This template is great for:
* 1) Landing pages where you don't want any distractions. You just want a sales or
* marketing funnel.
* 2) When you want to include this page in an iframe or remote content popup to avoid
@marklchaves
marklchaves / increment_gravity_forms_view_counter.php
Last active March 13, 2023 13:20
Bypass the default GF view counter logic so we count views for forms inside a popup only when the popup shows the form
<?php // Ignore this first line when copying to your child theme's functions.php file.
/**
* According to Gravity Forms Support on 9 March 2023, "The views column records the number of times the
* form markup is generated ... including when the form is redisplayed following validation errors.
* It's not strictly how many times the form was actually viewed."
*
* That means the Gravity Forms form view counter gets bumped up even if the form is hidden in a tab, popup, slider, and
* accordion (to name a few). Bottom line: don't trust the form view counter as a valid impression stat.
*/
@marklchaves
marklchaves / display-popup-trigger-settings-chrome-snippet.js
Last active March 2, 2023 08:45
Prompt for a popup ID number and then display the trigger settings for that popup ID in a table format.
const popupID = prompt("What's the popup ID number?");
if (typeof PUM !== 'undefined') {
let triggers = PUM.getSettings(popupID).triggers[0];
if (typeof triggers !== 'undefined') {
console.log(`%cTrigger Settings for Popup ID ${popupID}`,
"color: #b92099; font-size: 20px;");
console.table(triggers); // Triggers
if (typeof triggers.settings !== 'undefined') {
console.table(triggers.settings); // Cookies
//console.table(PUM.getSettings(input).triggers[0][1].settings); // Displays cookie name`
@marklchaves
marklchaves / create_wildcard_domain_cookie.php
Last active January 31, 2023 02:08
Create a wildcard domain cookie when a Popup Maker popup opens
@marklchaves
marklchaves / archive.php
Last active January 8, 2023 13:07
WP ULike Proof of Concept
<?php
/**
* Override the theme template for displaying archive pages.
*
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/
*
* @package WordPress
* @subpackage Twenty_Twenty_One
* @since Twenty Twenty-One 1.0
*/
@marklchaves
marklchaves / wrapImagesWithLink.js
Created November 6, 2022 07:43
Wrap images with an a (link) tag