Skip to content

Instantly share code, notes, and snippets.

View undfine's full-sized avatar

Dustin W undfine

  • Wilmington, NC
View GitHub Profile
<?php
/**
* Filters the uploads directory to use a custom structure for select post types
*/
add_filter('upload_dir', 'filter_uploads_dir_by_posttype');
function filter_uploads_dir_by_posttype( $upload ) {
global $post;
@undfine
undfine / wp_mods.php
Created February 22, 2023 22:48
A collection of useful unloads to streamline and secure Wordpress
<?php
// Disable XML RPC
add_filter( 'xmlrpc_enabled', '__return_false' );
// Disable Generator
add_filter('the_generator', '__return_empty_string');
//Disable emojis
add_action( 'init', 'dw_disable_emojis' );
@undfine
undfine / filter_post_thumbnail_url.php
Created March 2, 2023 10:11
Try to get an alternate post thumbnail from an image url field
// Try to get an alternate thumbnail from an image url field
add_filter( 'post_thumbnail_url', 'PREFIX_filter_post_thumbnail_url', 10, 2 );
function PREFIX_filter_post_thumbnail_url( $thumbnail_url, $post){
if ( empty($thumbnail_url) || $thumbnail_url == false ) {
// get the first instance of meta field 'property_image'
$image = get_post_meta($post->ID, 'property_image', true);
$image = is_array($image)? $image[0] : $image;
$thumbnail_url = ($image !== '') ? $image : '';
}
return $thumbnail_url;
@undfine
undfine / get_numeric.php
Last active March 2, 2023 10:49
Utility shortcode to output a custom field in a specific number format
/**
* register "get_numeric" shortcode
* utility shortcode to output a numeric custom field value in a number format
* uses the php function: number_format(number,decimals,decimalpoint,separator)
* defaults to comma separator and 0 decimals
* example:
* [get_numeric id="123" field="price" before="$" after=" USD" decimals="2" decimalpoint="." separator=","]
* field = '100000.1233' out = "$100,000.12 USD"
*/
add_shortcode('get_numeric', 'PREFIX_get_numeric_field');
@undfine
undfine / filter_property_get_metadata.php
Created March 2, 2023 11:06
Filter a metadata call for the post thumbnail on a custom post type to use the first image in a gallery field instead
/**
* filter meta-data returned for certain posts
*
* This makes it possible to access dynamic data related to a post object by simply referencing `$post->foo`.
* That keeps the calling code much cleaner than if it were to have to do something like
* `$foo = some_custom_logic( get_post_meta( $post->ID, 'bar', true ) ); echo esc_html( $foo )`.
*
* @param mixed $value
* @param int $post_id
* @param string $property_key
<?php
if ( !defined( 'ABSPATH' ) ) exit;
/*Plugin Name: Widget Custom Classes
Description: This plugin adds a class field to the widgets section
Version: 1.0
Tested up to: 5.6
*/
class WidgetClassField{
public function __construct() {
@undfine
undfine / cf7-submit.js
Last active December 7, 2023 21:40
GA4 event for Contact Form 7 - Successful submit
<!-- Form submit success -->
<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
// GA4 event with recommended standard dimensions
if ( event.hasOwnProperty('detail') && typeof gtag !== "undefined" ) {
gtag('event', 'generate_lead', {
'form_name': 'Contact Form', // change this to a recognizable name for your form
'form_id': event.detail.contactFormId
});
@undfine
undfine / Elementor-form-submit-event.js
Last active October 14, 2024 19:25
GA4 event for Elementor Pro forms (submit success)
jQuery( document ).ready(function(){
// the "on" listener must be added within the document ready() block, otherwise it does not fire.
jQuery( document ).on('submit_success', function( event ) {
//console.log('submit_success', event.target.name);
// test for existence of gtag to prevent loading
if (typeof gtag !== 'undefined') {
gtag('event', 'generate_lead', {
@undfine
undfine / simpleparallax-elementor.html
Last active May 19, 2023 13:27
SimpleParallax for Elementor
<script src="https://cdn.jsdelivr.net/npm/simple-parallax-js@5.6.2/dist/simpleParallax.min.js"></script>
<script>
var parallaxBg = document.querySelectorAll('.parallax-bg img');
new simpleParallax(parallaxBg, {
customWrapper: '.elementor-widget-container',
orientation: 'down',
scale: 1.25,
delay: 0.3,
transition: 'cubic-bezier(0,0,0,1)',
});
@undfine
undfine / fluentform-submit-success-event.js
Last active July 1, 2026 17:44
Fluentforms Submit Success event for GA4 / GTM + Meta
jQuery(document).ready(function() {
jQuery(document).on('fluentform_submission_success', function( event ) {
if (typeof gtag !== 'undefined') {
gtag('event', 'form_submit_success', {
'form_name': 'Contact Form',
'form_id': event.target.name
});
} else {
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({