Skip to content

Instantly share code, notes, and snippets.

@AMNDesign
AMNDesign / functions.php
Last active October 10, 2018 17:47
Dynamically populate Gravity Forms fields with WordPress user info for logged in users using get_currentuserinfo().
<?php
//* Using the Gravity Forms editor, be sure to check "Allow field to be populated dynamically under Advanced Options
//* You will need to set the Field Parameter Name value to work with the filter as follows: gform_field_value_$parameter_name
//* Dynamically populate first name for logged in users
add_filter('gform_field_value_first_name', 'populate_first_name');
function populate_first_name($value){
global $current_user;
get_currentuserinfo();
return $current_user->user_firstname;
@AMNDesign
AMNDesign / functions.php
Created August 28, 2013 21:03
Add a "read more" link after both manual excerpts and regular excerpts and customize the link text for custom post types in WordPress.
<?php
//* Add read more link after both manual excerpts and regular excerpts and customize link text for custom post types
add_filter('the_excerpt', 'amn_manual_excerpt_read_more_link');
function amn_manual_excerpt_read_more_link($output) {
global $post;
if ( get_post_type() == 'my_custom_post_type_slug' ) {
$link_text = 'My CPT Read More Text';
} else {
$link_text = 'Read More';
}
@AMNDesign
AMNDesign / functions.php
Last active December 21, 2015 21:09
Add a "read more" link after both manual excerpts and regular excerpts in WordPress.
<?php
//* Add read more link after both manual excerpts and regular excerpts
add_filter('the_excerpt', 'amn_manual_excerpt_read_more_link');
function amn_manual_excerpt_read_more_link($output) {
global $post;
return substr($output,0,-5).'... <a href="' . get_permalink($post->ID) . '">Read More</a>.</p>';
}
@AMNDesign
AMNDesign / functions.php
Last active December 21, 2015 21:09
Include custom post types in tag archive and category archive search results in WordPress.
<?php
//* Include custom post types in tag archive and category archive search results
add_filter( 'pre_get_posts', 'amn_get_posts' );
function amn_get_posts( $query ) {
if ( ( is_tag() || is_category() ) && false == $query->query_vars['suppress_filters'] )
$query->set( 'post_type', array( 'post', 'page', 'attachment', 'my_custom_post_type' ) );
return $query;
}
@AMNDesign
AMNDesign / functions.php
Created August 27, 2013 22:04
Remove AddThis from specific custom post types in WordPress.
<?php
//* Remove AddThis from specific custom post types
add_filter('addthis_post_exclude', 'amn_addthis_post_exclude_filter');
function amn_addthis_post_exclude_filter($display) {
if ( in_array(get_post_type(), array('custom_post_type_1', 'custom_post_type_2','custom_post_type_3')) )
$display = false;
return $display;
}
@AMNDesign
AMNDesign / functions.php
Created August 27, 2013 21:54
Customize the default search text and search form using the Genesis Framework.
<?php
//* Customize Search Text
add_filter( 'genesis_search_text', 'amn_search_text');
function amn_search_text() {
return esc_attr__( 'Search this website...', 'genesis' );
}
//* Customize Search Form
add_filter( 'genesis_search_form', 'amn_search_form', 10, 4);
function amn_search_form( $form, $search_text, $button_text, $label ) {
@AMNDesign
AMNDesign / functions.php
Last active December 21, 2015 20:09
Add support for structural wraps using the Genesis Framework.
<?php
//* Add support for structural wraps
add_theme_support( 'genesis-structural-wraps', array(
'header',
'nav',
'subnav',
'site-inner',
'footer-widgets',
'footer'
) );
@AMNDesign
AMNDesign / functions.php
Created August 27, 2013 21:40
Remove the default "G" favicon using the Genesis Framework.
<?php
//* Remove default Genesis "G" favicon
remove_action('genesis_meta', 'genesis_load_favicon'); // Genesis 1.9
remove_action('wp_head', 'genesis_load_favicon'); // Genesis 2.0
@AMNDesign
AMNDesign / functions.php
Created August 27, 2013 21:36
Add excerpts post type support for pages in WordPress.
<?php
//* Add excerpts post type support for pages
add_action('init', 'amn_page_excerpts');
function amn_page_excerpts() {
add_post_type_support( 'page', 'excerpt');
}
@AMNDesign
AMNDesign / functions.php
Created August 27, 2013 21:31
Add custom image sizes to WordPress and make them available within the Media Library Attachment Display Settings options.
<?php
//* Add custom image sizes to WordPress
add_image_size( 'featured', 690, 180, TRUE );
add_image_size( 'full_width', 960);
add_image_size( 'grid', 300, 150, TRUE );
add_image_size( 'small_thumbnail', 100, 100, TRUE );
add_image_size( 'micro_thumbnail', 75, 75, TRUE );
//* Make custom sizes available within the WordPress Media Library Attachment Display Settings
add_filter( 'image_size_names_choose', 'amn_image_sizes_choose' );