// 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 );
}
Suppress Hero on Pages Without Featured Image
@replace {{element_id}}
add_filter( 'generate_header_element_display', function( $display, $element_id ) {
if ( {{element_id}} === $element_id ) {
if ( ! has_post_thumbnail() )
$display = false;
}
return $display;
}, 10, 2 );
Numbered List Rows in Gravity Forms
/* Numbered List Rows in Gravity Forms */
body .gform_wrapper .gform_fields .gfield_list {
counter-reset: gf-list-counter;
}
body .gform_wrapper .gform_fields .gfield_list .gfield_list_header::before {
width: 1.5em;
content: '';
}
body .gform_wrapper .gform_fields .gfield_list .gfield_list_group::before {
width: 1.5em;
line-height: 2.25;
font-weight: bold;
counter-increment: gf-list-counter;
content: counter(gf-list-counter);
}
Disallow Specific Terms in WordPress Search
@replace @arr $restricted
// Disallow users from searching specific terms on your site
add_filter( 'pre_get_posts', function( $query ) {
$restricted = array(
'term-1',
'term-2'
);
if ( $query->is_search && $query->is_main_query() ) {
$stripped = trim( str_replace( $restricted, '', $query->get('s') ) );
if ( $stripped == '' )
$query->set( 'p', -1 );
else
$query->set( 's', $stripped );
}
} );
Order Form List Table By Most Recent
// Order form list table by most recent
add_filter( 'gform_form_list_forms', function( $forms, $search_query, $active, $sort_column, $sort_direction, $trash ) {
if ( ! rgget( 'orderby' ) ) {
usort( $forms, function( $a, $b ) {
return $b->id <=> $a->id;
} );
}
return $forms;
}, 10, 6 );
Remove Title Link From All WP Show Posts Posts
// Remove the title link from all posts queried via WP Show Posts
add_filter( 'wpsp_disable_title_link', '__return_true' );
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 );
Prevent Right-Aligned Nav Sub-Menu w/ Right Dropdown Direction From Overflowing Viewport
/* Prevent sub-menu dropdown of the final item in right-aligned navigation from overflowing the viewport */
.dropdown-hover .main-navigation:not(.toggled) ul li:last-child:hover>ul {
right: 0;
}
.dropdown-hover .main-navigation:not(.toggled) ul li:last-child ul li:hover>ul {
left: -100%;
}
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;
} );
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>';
}
} );
Remove Image Link From All WP Show Posts Posts
// Remove the image link from all posts queried via WP Show Posts
add_filter( 'wpsp_disable_image_link', '__return_true' );
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 );
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;
}
}
} );