Sort by: Recently Added Likes

Add Google Font(s) to Typography Customizer

@replace font-slug, font[name]:@str, font[variants]:@arr, font[category]:@str

// Add Google Fonts to the typography font options in the customizer
add_filter( 'generate_typography_customize_list', function ( $fonts ) {

   $fonts['monoton'] = array( 
      'name' => 'Monoton',
      'variants' => array( '400' ),
      'category' => 'cursive'
   );

   $fonts['fanwood_text'] = array(
      'name' => 'Fanwood Text',
      'variants' => array( '400', '400i' ),
      'category' => 'serif'
   );
	
   return $fonts;

} );

Source

Increase width of form editor sidebar

// Increase width of form editor sidebar
add_action( 'admin_print_styles', function() {

    if ( class_exists( 'GFCommon' ) && GFCommon::is_form_editor() ) {

        echo '<style>
                .gforms_edit_form .form_editor_fields_container { max-width: calc( 100% - 744px ); }
                .gforms_edit_form .form_editor_fields_container.droppable { padding-right: 712px; }
                .gforms_edit_form .editor-sidebar .sidebar,
                .gforms_edit_form .editor-sidebar .sidebar .sidebar__nav { width: 520px; }
                .gforms_edit_form .editor-sidebar .sidebar .add-buttons li { width: 25%; }
              </style>';

    }

} );

#

Add CSS Class to Filled Fields

@replace {{class}}

<?php
// Checks whether form inputs are filled and adds a targetable class if they have value
add_action( 'wp_footer', function () { ?>

   <script type="text/javascript">
      jQuery(document).ready( function() {
         function checkFilledInputs() {
            jQuery('textarea,input').each( function() { toggleFilledInputs(this); });
            jQuery('textarea,input').change( function() { toggleFilledInputs(this); });
         }

         function toggleFilledInputs(e) {
            if ( jQuery(e).val().trim().length > 0 ) {
               jQuery(e).addClass('{{class}}');
            } else {
               jQuery(e).removeClass('{{class}}');
            }
         }

         jQuery(document).bind('gform_post_render', function() { checkFilledInputs(); });
         
         checkFilledInputs();
      });
   </script>

<?php } );

#

Fix Center Alignment of Main Nav Menu Items With Children

@replace {{gp-layout-setting-menu-item-width}}

/* Fixes center alignment of main nav menu items that show children in a dropdown */
.main-navigation.mobile-header-navigation ul li.menu-item-has-children a {
   padding-right: {{gp-layout-setting-menu-item-width}};
}
.main-navigation.mobile-header-navigation ul li.menu-item-has-children span.dropdown-menu-toggle {
   position: absolute;
   right: 0;
}

#

Change Header Logo HREF

@replace {{link}}

// Change the URL to which the header logo links
add_filter( 'generate_logo_href', function( $url ) {
    return '{{link}}';
});

#

Set parent for post created with APC to embed post

@replace {{form_id}}

// Set parent for post created with APC to post on which form is embedded
add_action( 'gform_advancedpostcreation_post_after_creation_{{form_id}}',

    function( $post_id, $feed, $entry, $form ) {

        wp_update_post( array(
            'ID' => $post_id,
            'post_parent' => GFCommon::replace_variables( '{embed_post:ID}', $form, $entry )
        ) );

    },

10, 4 );

#

Perform Function On Any Site of Multisite Network

/**
 *  Perform any function on any site on the network
 *
 *  @param    integer         $site_id   site on which to perform the function
 *  @param    string|array    $action    function name to perform
 *  @param    array           $args      parameters passed as an indexed array
 *  @return
 */
function do_network_request( $site_id, $action, $args = array() ) {

   switch_to_blog( $site_id );

      if ( ( is_string( $action ) && function_exists( $action ) ) || ( is_array( $action ) && method_exists( ...$action ) ) )
         $result = call_user_func( $action, ...$args );
      else
         $result = NULL;

   restore_current_blog();

   return $result;

} // end do_network_request

#

Remove Welcome Panel

// Remove the welcome panel for new WordPress installs
remove_action( 'welcome_panel', 'wp_welcome_panel' );

#

Remove inactive forms from form switcher

// Remove inactive forms from form switcher
add_filter( 'gform_form_switcher_forms', function( $forms ) {

    $forms = array_filter( $forms, function( $form ) {
        return rgobj( $form, 'is_active' );
    } );

    return $forms;

} );

#

Replace Numbered Months with Named Months in Date Field

<?php // Replace the numbered months with named months in a Gravity Forms dropdown date field
add_action( 'wp_footer', function () { ?>

   <script type="text/javascript">
      jQuery(document).ready(function( $ ) {
         $('.gfield_date_dropdown_month select option').each( function(i, option) {
            switch( option.value ) {
               case '1': option.innerHTML = 'January'; break;
               case '2': option.innerHTML = 'February'; break;
               case '3': option.innerHTML = 'March'; break;
               case '4': option.innerHTML = 'April'; break;
               case '5': option.innerHTML = 'May'; break;
               case '6': option.innerHTML = 'June'; break;
               case '7': option.innerHTML = 'July'; break;
               case '8': option.innerHTML = 'August'; break;
               case '9': option.innerHTML = 'September'; break;
               case '10': option.innerHTML = 'October'; break;
               case '11': option.innerHTML = 'November'; break;
               case '12': option.innerHTML = 'December'; break;
            }
         });
      });
   </script>

<?php } );

#

Auto-Link Caption to Same URL As the Image’s Link

Add link-the-caption as Additional CSS Class on image block. Caption should contain no other links.

// Auto-link image caption to the same URL as that to which the image has been linked
jQuery(document).ready(function( $ ) {

   $('.link-the-caption').each( function() {

      let image_link = $(this).attr('href');
      let image_caption = $(this).next().html();

      $(this).next().html('<a href="'+image_link+'">'+image_caption+'</a>');

   });

});

#