Skip to content

Instantly share code, notes, and snippets.

View chriswagoner's full-sized avatar

Chris Wagoner chriswagoner

  • Chicago
View GitHub Profile
function add_image_insert_override($sizes){
unset( $sizes['thumbnail']);
unset( $sizes['medium']);
unset( $sizes['large']);
return $sizes;
}
add_filter('intermediate_image_sizes_advanced', 'add_image_insert_override' );
@chriswagoner
chriswagoner / prevent-category-reordering.php
Last active May 25, 2017 16:49
Prevent Selected Categories from Reordering (Admin)
function prevent_category_reorder($args) {
$args['checked_ontop'] = false;
return $args;
}
add_filter('wp_terms_checklist_args','prevent_category_reorder');
@chriswagoner
chriswagoner / wp-replace-text.php
Created June 23, 2017 17:28
Wordpress Replace Text
/** FILTER THE TEXT, THEN EXECUTE A FUNCTION THAT USES THE FILTER **/
add_filter( 'gettext', 'grab_text', 20, 3 );
function grab_text( $translated_text, $text, $domain ) {
if ( $translated_text == 'Barcode' ) {
$translated_text = 'UPC';
}
return $translated_text;
}
@chriswagoner
chriswagoner / wp-admin-css.php
Created July 26, 2017 17:57
Pop some CSS into the WordPress Admin
add_action('admin_head', 'my_stuff');
function my_stuff() {
echo '<style>
.nice-class {
border: 1px solid red;
}
</style>';
}
@chriswagoner
chriswagoner / get-current-author.php
Created March 13, 2018 19:22
Get Author of Current Post
add_shortcode('author-name', 'author_name_shortcode_handler');
function author_name_shortcode_handler($atts,$content=null){
if (!is_single()) return;
global $wp_query;
$user_id = $wp_query->post->post_author;
$name = get_user_meta($user_id, 'first_name', true) . ' ' . get_user_meta($user_id, 'last_name', true);
@chriswagoner
chriswagoner / wpcf-time-to-read.php
Created March 14, 2018 21:08
Wordpress Time To Read via Custom Meta Boxes
/*
CREATING A CUSTOM TIME TO READ FUNCTION BECAUSE WE'RE USING CUSTOM POST FIELDS
---------------------------------------------------------------------------------------------------- */
add_shortcode('my-custom-readtime', 'reading_time');
function reading_time() {
global $post;
$content = get_post_field( 'post_content', $post->ID );
$content .= types_render_field('field_name', array( "id"=>$post->ID) );
$content .= types_render_field('field_name', array( "id"=>$post->ID) ); // Add more fields as needed
@chriswagoner
chriswagoner / GF_field_populate.php
Created April 24, 2018 19:36
Pop some info into a Gravity Form field (Gravity Perks Req)
/**
* Configure the Date and Time Automatic Entry
*
*/
new GW_Populate_Date( array(
'form_id' => 9,
'target_field_id' => 111,
'format' => 'mdYHis'
) );
@chriswagoner
chriswagoner / add-nested-shortcode.php
Last active May 8, 2018 18:49
Nested Shortcode via Filter
/**
* This will allow you to grab the output of an existing shortcode (you're probably already using)
* and execute the shortcodes you're using inside of it.
*/
function my_function_name ( $output, $tag ) {
if ( 'existing_shortcode_name' != $tag ) {
return $output;
}
$output = do_shortcode($output);
return $output;
@chriswagoner
chriswagoner / woo-share.php
Created May 22, 2018 12:41
Customize the Share Buttons in WooCommerce
// Adding Anything I Want Where the Share Buttons Go in WooCommerce
function insert_myshare_buttons() {
echo do_shortcode( '[myshortcode value="here"]' );
}
add_action( 'woocommerce_share', 'insert_myshare_buttons' );
@chriswagoner
chriswagoner / mem-bump.php
Created May 25, 2018 14:49
Let's bump that WordPress memory up!
/* This goes in that config file */
define('WP_MEMORY_LIMIT', '256M');
define( 'WP_MAX_MEMORY_LIMIT', '256M' );