Skip to content

Instantly share code, notes, and snippets.

@kaelri
kaelri / wordpress-track-and-redirect-media.php
Last active June 16, 2022 20:33
On WordPress singular attachment pages, send a custom Data Layer event to Google Tag Manager and then redirect to the raw file.
<?php
add_action( 'wp_footer', function() {
if ( !is_attachment() ) return;
$file_url = wp_get_attachment_url( get_the_ID() );
?><script>
@kaelri
kaelri / github_actions_ftp_deploy_example.yml
Created May 11, 2022 14:55
Use git-ftp to sync the latest commit’s files to an (S)FTP destination.
name: Publish to Production
on:
push:
branches: [ master ]
jobs:
web-deploy:
name: Deploy
runs-on: ubuntu-latest
steps:
- name: Get Code
<?php
add_action( 'get_header', function() {
if ( !is_attachment() ) return;
$file_url = wp_get_attachment_url( get_the_ID() );
wp_redirect( $file_url );
<?php
add_action( 'get_header', function() {
if ( !is_attachment() ) return;
$file_url = wp_get_attachment_url( get_the_ID() );
$file_name = basename( $file_url );
header( sprintf('Content-type: %s', get_post_mime_type() ) );
@kaelri
kaelri / wordpress-conditional-block-css.php
Last active July 5, 2023 17:57
wordpress-conditional-block-css
<?php
add_action( 'wp_enqueue_scripts', 'my_block_enqueue_scripts' );
function my_block_enqueue_scripts() {
wp_enqueue_style( 'my-normal-css' );
// Do this only if the current post/page has an instance of the related block.
if ( has_block('my-block-name') ) {
@kaelri
kaelri / advanced-accordion.php
Created December 17, 2024 16:38
JupiterX <=> Elementor 3.26 Scheme Upgrade
<?php
namespace JupiterX_Core\Raven\Modules\Advanced_Accordion\Widgets;
defined( 'ABSPATH' ) || die();
use JupiterX_Core\Raven\Controls\Query;
use JupiterX_Core\Raven\Base\Base_Widget;
use Elementor\Icons_Manager;
use Elementor\Controls_Manager;
/**
* Create or update a list of contacts in Hubspot.
* @param registrants Array of contact objects, e.g. from an external data source.
* @returns The JSON response from Hubspot.
*/
async function hubspotCreateOrUpdateContacts( contacts, hubspotAPIKey ) {
let hubspotContacts = contacts.map( registrant => {
return {