Sort by: Recently Added Likes

Auto-Link Twitter Usernames

// Automatically link Twitter usernames (i.e. any text in the form of @username)
add_filter( 'the_content', 'typewheel_link_twitter_username' );   
add_filter( 'the_excerpt', 'typewheel_link_twitter_username' );
add_filter( 'comment_text', 'typewheel_link_twitter_username' );

function typewheel_link_twitter_username( $content ) {
   return preg_replace( '/([^a-zA-Z0-9-_&])@([0-9a-zA-Z_]+)/', '$1<a href="https://twitter.com/$2" target="_blank" rel="nofollow">@$2</a>', $content );
}
 

Source

Customize Recovery Mode Email Recipient

@replace {{email}}

// Customize the email address to which recovery mode email is sent when site encounters a fatal error
add_filter( 'recovery_mode_email', function( $email ) {

    $email['to'] = '{{email}}';

    return $email;

} );

#

Change Loading Spinner

@replace {{img-src}}

// Set a custom image src for the spinner that runs when processing AJAX requests
add_filter( 'gform_ajax_spinner_url', function( $image_src, $form ) {
   return '{{img-src}}';
}, 10, 2 );

#

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 } );

#

Redirect Solitary Search Results to the Post

// If a search results returns only a single post, then redirect the user to that post
add_action( 'template_redirect', function () {

   if ( is_search() ) {

      global $wp_query;

      if ( $wp_query->post_count == 1 && $wp_query->max_num_pages == 1 ) {

         wp_redirect( get_permalink( $wp_query->posts['0']->ID ) );
         exit;

      }

   }

} );

Source

Set Default Customizer Color Palette

@replace @arr

// Set 8 colors that will be used to fill the color picker palette in the Customizer
add_filter( 'generate_default_color_palettes', function ( $palettes ) {
   return array(
      '#040404',
      '#5b5549',
      '#9b5c4d',
      '#d3ac58',
      '#296a7f',
      '#272727',
      '#adada8',
      '#f5f5f5',
   );
} );

Source

Move Navigation Below Page Header

// Renders the navigation below the page header instead of before
add_action( 'after_setup_theme', function () {

   remove_action( 'generate_after_header', 'generate_add_navigation_after_header', 5 );
   add_action( 'generate_after_header', 'generate_add_navigation_after_header', 15 );

} );

Source

Limit Countries

@replace {{_formID}}

// Filter the countries that are selectable in an address field
add_filter( 'gform_pre_render{{_formID}}', 'typewheel_limit_countries' );
add_filter( 'gform_pre_validation{{_formID}}', 'typewheel_limit_countries' );
add_filter( 'gform_pre_submission_filter{{_formID}}', 'typewheel_limit_countries' );
add_filter( 'gform_admin_pre_render{{_formID}}', 'typewheel_limit_countries' );

function typewheel_limit_countries( $form ) {

  add_filter( 'gform_countries', function( $countries ) {
    return array( 'Brazil', 'United States', 'Netherlands', 'United Kingdom' );
  });

  return $form;

}

#

Prevent Submission When Pressing Enter

<?php // Disables form submission when pressing Enter, unless user has tabbed to a form button.
add_action( 'gform_pre_render', function ( $form ) { ?>

   <script type="text/javascript">
      jQuery(document).bind('gform_post_render', function() {
         jQuery(document).on( 'keypress', '.gform_wrapper', function (e) {
            var code = e.keyCode || e.which;
            if ( code == 13 && ! jQuery( e.target ).is( 'textarea,input[type="submit"],input[type="button"]' ) ) {
               e.preventDefault();
               return false;
            }
         });
      });
   </script>

   <?php return $form;

} );

#

Customizing Your 404 Page Not Found

@replace {{title}}, {{text}}

// Set a custom title for the 404 page
add_filter( 'generate_404_title', function ( $title ) {
   return '{{title}}';
} );

// Set custom text for the 404 page
add_filter( 'generate_404_text', function ( $text ) {
   return '{{text}}';
} );

// Hide the search form from content area on the 404 page
add_filter( 'get_search_form', function ( $form ) {

   if ( is_404() && did_action( 'generate_after_entry_header' ) && ! did_action( 'generate_after_content' ) )
      return '';

   return $form;

} );

#

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

Remove Welcome Panel

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

#