Skip to content

Instantly share code, notes, and snippets.

@infocities
infocities / clear_gravity_form_default_values.js
Created November 26, 2024 07:14 — forked from jasperf/clear_gravity_form_default_values.js
Clear default values in Gravity Forms and place them back in on blur if they are empty
jQuery(document).ready(function($) {
jQuery.fn.cleardefault = function() {
return this.focus(function() {
if( this.value == this.defaultValue ) {
this.value = "";
}
}).blur(function() {
if( !this.value.length ) {
this.value = this.defaultValue;
@infocities
infocities / acf-gravity-forms-field.php
Created September 14, 2024 00:30 — forked from psaikali/acf-gravity-forms-field.php
Populate ACF select field options with Gravity Forms to select a specific form
<?php
/**
* Populate ACF select field options with Gravity Forms forms
*/
function acf_populate_gf_forms_ids( $field ) {
if ( class_exists( 'GFFormsModel' ) ) {
$choices = [];
foreach ( \GFFormsModel::get_forms() as $form ) {
$choices[ $form->id ] = $form->title;
@infocities
infocities / README.md
Created September 14, 2024 00:13 — forked from ControlledChaos/README.md
Add srcset and sizes attributes to Advanced Custom Fields image uploads.

ACF Responsive Images

WordPress Snippet

Adds the srcset and sizes attributes to ACF image uploads. Requires installation of the Advanced Custom Fields plugin.

NOTE: ACF image field must be set to return the ID.

NOTE: WordPress needs image sizes with equal aspect ratios in order to generate the srcset, and does not use srcset when images are added as "Full Size".

@infocities
infocities / slider.js
Created September 14, 2024 00:09 — forked from khoipro/slider.js
Load swiper slides lazyload (with <noscript> tag) for each slide
import { select, selectAll, hasClass, removeClass, loadNoscriptContent } from 'lib/dom'
import Swiper, { Navigation } from 'swiper'
export default el => {
const sliderEl = select('.js-slider', el)
const slideEls = selectAll('.swiper-slide', el)
if (sliderEl) {
const swiper = new Swiper(sliderEl, {
freeMode: true,
@infocities
infocities / webflow.html
Created June 29, 2024 16:08 — forked from diegoliv/webflow.html
Lenis + Webflow (with anchor links workaround)
<script src="https://cdn.jsdelivr.net/gh/studio-freight/[email protected]/bundled/lenis.js"></script>
<script>
if (!document.querySelector("html").classList.contains('w-editor')){
const lenis = new Lenis({
duration: 1.2,
easing: (t) => Math.min(1, 1.001 - Math.pow(2, -10 * t)), // https://www.desmos.com/calculator/brs54l4xou
direction: 'vertical', // vertical, horizontal
gestureDirection: 'vertical', // vertical, horizontal, both
smooth: true,
@infocities
infocities / functions.php
Created May 19, 2024 23:02 — forked from hmowais/functions.php
Show Custom Post Types in Gravity Form Select Field
<?php
/* Show Custom Post Types in Gravity Form Select Field */
add_filter( 'gform_pre_render_2', 'populate_cpt_titles' );
add_filter( 'gform_pre_validation_2', 'populate_cpt_titles' );
add_filter( 'gform_pre_submission_filter_2', 'populate_cpt_titles' );
add_filter( 'gform_admin_pre_render_2', 'populate_cpt_titles' );
function populate_cpt_titles( $form ) {
foreach ( $form['fields'] as &$field ) {
if ( $field->type != 'select' || strpos( $field->cssClass, 'populate_cpt_titles' ) === false ) {
continue;
@infocities
infocities / README.md
Created May 10, 2024 01:52 — forked from Striffly/README.md
Gravity Forms with AJAX, conditional logic, pages transitions (compatible with Barba.js, Taxi.js, Highway.js, ...)

The following code enables the use of Gravity Forms (2.8.7 as of now) with the following features:

  • AJAX loading, 100% functional
  • Functional with page transitions (Barba.js, Taxi.js, Highway.js)
  • Enqueue Gravity Forms scripts used by each forms (including conditional logic scripts)
  • Works with recaptcha (with recent version of Gravity Forms reCAPTCHA Add-On, scripts are automaticaly enqueued)
  • Keep the form displayed after submission (optional)
  • Scripts moved to footer (optional)

The code was initially integrated into projects using roots/sage. I adapted the code for integration into "vanilla" WordPress projects but I have less feedback compared to the use I have with my stack, so feel free to let me know if there are any errors in the comments!

@infocities
infocities / bs5-navwalker.php
Created April 4, 2024 06:50 — forked from cdsaenz/bs5-navwalker.php
Wordpress Bootstrap 5 Nav Walker With Multiple Levels
<?php
/**
* CSDev - Bootstrap 5 wp_nav_menu walker
* Supports WP MultiLevel menus
* Based on https://github.com/AlexWebLab/bootstrap-5-wordpress-navbar-walker
* Requires additional CSS fixes
* CSS at https://gist.github.com/cdsaenz/d401330ba9705cfe7c18b19634c83004
* CHANGE: removed custom display_element. Just call the menu with a $depth of 3 or more.
*/
class bs5_Walker extends Walker_Nav_menu
@infocities
infocities / gravity-forms-confirmation-remain.php
Created April 1, 2024 06:26 — forked from davidwolfpaw/gravity-forms-confirmation-remain.php
Keep Gravity Forms Displayed After Submission
<?php
// Allow the Gravity form to stay on the page when confirmation displays.
add_filter( 'gform_pre_submission_filter', 'dw_show_confirmation_and_form' );
function dw_show_confirmation_and_form( $form ) {
// Inserts a shortcode for the form without title or description
$shortcode = '[gravityform id="' . $form['id'] . '" title="false" description="false"]';
// Ensures that new lines are not added to HTML Markup
ob_start();
@infocities
infocities / gist:0ed3def2019544c8cedfea82e5057586
Created April 1, 2024 02:49 — forked from 465media/gist:17664b045de75deafcb2b99695d22df9
Set default "From Email" for Gravity Forms notifications using WordPress domain.
/**
* Set default "From Email" for Gravity Forms notifications using WordPress domain.
*/
function override_gravityforms_from_email( $email, $notification ) {
// Get the WordPress site URL and extract the domain.
$site_url = get_site_url();
$parsed_url = parse_url( $site_url );
$domain = isset( $parsed_url['host'] ) ? $parsed_url['host'] : '';
if ( isset( $email['from'] ) && $email['from'] === '{admin_email}' ) {
$email['from'] = 'no-reply@' . $domain;