Skip to content

Instantly share code, notes, and snippets.

View hirejordansmith's full-sized avatar

Jordan Smith hirejordansmith

View GitHub Profile
@hirejordansmith
hirejordansmith / insert-content-wordpress-after-certain-amount-characters-words.php
Created December 6, 2016 13:58
Insert Content in WordPress after a certain amount of characters or words
<?php
add_filter('the_content', 'hjs_insert_content_after_chars_words');
function hjs_insert_content_after_chars_words($content) {
// only do this if post is longer than 1000 characters
$enable_length = 1500;
// insert after the first </p> after 500 characters
$after_character = 1500;
if (is_single() && strlen($content) > $enable_length) {
$before_content = substr($content, 0, $after_character);
$after_content = substr($content, $after_character);
@hirejordansmith
hirejordansmith / events-recurring.php
Created December 18, 2016 12:34
Events Recurring with Thumbnail Support
<?php
/**
* Recurring Events
*
* @package BE-Events-Calendar
* @since 1.0.0
* @link https://github.com/billerickson/BE-Events-Calendar
* @author Bill Erickson <bill@billerickson.net>
* @copyright Copyright (c) 2014, Bill Erickson
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
@hirejordansmith
hirejordansmith / woocommerce-class-values.php
Last active April 22, 2024 14:20
WooCommerce Class Values
<?php
// Returns subtotal price ($5.00)
$cart_subtotal = WC()->cart->get_cart_subtotal();
// Returns subtotal number value (5)
$cart_subtotal = WC()->cart->subtotal;
/*========================================
Single Product
@hirejordansmith
hirejordansmith / functions.php
Created September 26, 2019 13:57
Add support for ACF custom fields to WooCommerce Attributes
<?php
// Adds a custom rule type.
add_filter( 'acf/location/rule_types', function( $choices ){
$choices[ __("Other",'acf') ]['wc_prod_attr'] = 'WC Product Attribute';
return $choices;
} );
// Adds custom rule values.
add_filter( 'acf/location/rule_values/wc_prod_attr', function( $choices ){
@hirejordansmith
hirejordansmith / insert-content-wordpress-after-certain-amount-paragraphs.php
Created December 6, 2016 13:59
Insert Content in WordPress after a certain amount of paragraphs
<?php
//Insert ads after second paragraph of single post content.
add_filter( 'the_content', 'prefix_insert_post_ads' );
function prefix_insert_post_ads( $content ) {
$ad_code = '<div>Ads code goes here</div>';
if ( is_single() && ! is_admin() ) {
return prefix_insert_after_paragraph( $ad_code, 2, $content );
}
return $content;
}
@hirejordansmith
hirejordansmith / magnific-popup-gallery-image-plus-video.js
Last active December 6, 2023 22:28
How to show images and video in Magnific Popup Gallery
@hirejordansmith
hirejordansmith / better-woocommerce-cart-checkout-styles.css
Last active March 27, 2023 23:12
Better WooCommerce Cart and Checkout Styles
/* Woocommerce Styles */
/*
A couple things to note...
1. This code was written very specifically for my base child theme so it might not work out of the box with every theme.
I have it here mostly to share with anyone who might be looking to do the same thing I was.
2. I generally add my WooCommerce CSS overrides to a custom-woo.css file then use wp_enqueue_style() to call it
so that it enqueues after the default WooCommerce Stylesheets
@hirejordansmith
hirejordansmith / facet-wp-infinite-scroll.js
Last active March 13, 2023 18:25 — forked from robneu/facet-wp-infinite-scroll.js
Infinite scroll for FacetWP
/* globals FWP */
/**
* JavaScript for FacetWP Infinite Scroll
*/
( function( $ ) {
'use-strict';
var throttleTimer = null;
var throttleDelay = 100;
@hirejordansmith
hirejordansmith / pre-populate-gf-dropdown-with-affiliates.php
Last active March 25, 2021 01:29
Pre-populate a Gravity Forms Dropdown field with AffiliateWP Affiliates
<?php
// Add filters for Form ID 8
add_filter( 'gform_pre_render_8', 'populate_posts' );
add_filter( 'gform_pre_validation_8', 'populate_posts' );
add_filter( 'gform_pre_submission_filter_8', 'populate_posts' );
add_filter( 'gform_admin_pre_render_8', 'populate_posts' );
function populate_posts( $form ) {
// Loop through each field searching for any "select" field with the class "populate-affs"
@hirejordansmith
hirejordansmith / time-based-conditional-logic-gravity-forms.php
Created September 30, 2016 08:34
How to setup time-based conditional logic for Gravity Forms
<?php
add_filter( 'gform_field_value_time', function() {
return date( 'G.i', current_time( 'timestamp' ) );
} );