Skip to content

Instantly share code, notes, and snippets.

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

mark l chaves marklchaves

🏄‍♂️
View GitHub Profile
@marklchaves
marklchaves / help-scout-custom-code-top-banner-css.html
Last active March 28, 2024 09:19
Help Scout Docs Top Banner Custom CSS and JavaScript
<!-- Winter 2004 Banner -->
<style>
body {
margin-top: 113px !important;
}
#winter-2004-banner.hidden {
top: -113px;
}
#winter-2004-banner {
@marklchaves
marklchaves / template-parts-header-example.html
Created February 25, 2024 09:59
Content Control restrict header example
<!-- wp:group {"style":{"spacing":{"padding":{"right":"var:preset|spacing|10","left":"var:preset|spacing|10","top":"var:preset|spacing|10","bottom":"var:preset|spacing|10"}}},"backgroundColor":"accent","layout":{"type":"flex","flexWrap":"nowrap","justifyContent":"space-between"},"contentControls":{"enabled":false,"rules":{}}} -->
<div class="wp-block-group has-accent-background-color has-background" style="padding-top:var(--wp--preset--spacing--10);padding-right:var(--wp--preset--spacing--10);padding-bottom:var(--wp--preset--spacing--10);padding-left:var(--wp--preset--spacing--10)"><!-- wp:site-logo {"width":79,"shouldSyncIcon":true} /-->
<!-- wp:paragraph {"fontSize":"large","contentControls":{"enabled":false,"rules":{"user":{"userStatus":"logged_out","roleMatch":"any","userRoles":[]}}}} -->
<p class="has-large-font-size">Logged-out Menu</p>
<!-- /wp:paragraph -->
<!-- wp:navigation {"ref":56,"layout":{"type":"flex"},"fontSize":"large","contentControls":{"enabled":false,"rules":{"user":{"userStatus":"logge
@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 / 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 / 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 March 3, 2025 11:32
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.
*/