Skip to content

Instantly share code, notes, and snippets.

😎
Writing Code

Alex Mills Viper007Bond

Block or report user

Report or block Viper007Bond

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Viper007Bond
Viper007Bond / functions.php
Created Sep 18, 2017
Change who can use Regenerate Thumbnails
View functions.php
<?php
## Copy/paste the below code into your theme's functions.php file or a new plugin.
add_filter( 'regenerate_thumbs_cap', function( $capability ) {
// See https://codex.wordpress.org/Roles_and_Capabilities
return 'upload_files';
} );
@Viper007Bond
Viper007Bond / gist:797685e2ef6e75e7289f
Created Mar 28, 2015
Include pages in category archive pages
View gist:797685e2ef6e75e7289f
<?php
/**
* Copy paste the below code into your theme's functions.php file.
* You could add it to a plugin instead, but it's just easier to
* add it to your theme's functions.php. The only drawback to this
* is if you switch themes, this functionality will stop working.
*
* --Alex Mills
* Questions? Contact me: http://www.viper007bond.com/contact/
@Viper007Bond
Viper007Bond / gist:10040166
Created Apr 7, 2014
Default WordPress to use 4 column galleries
View gist:10040166
<?php
add_filter( 'shortcode_atts_gallery', 'sheri_galleries_default_to_four_columns', 10, 3 );
function sheri_galleries_default_to_four_columns( $atts, $defaults, $raw_atts ) {
// Don't override manually-set number of columns
if ( ! empty( $raw_atts['columns'] ) ) {
return $atts;
}
View gist:6136585
<?php
if ( !function_exists( 'wpcom_vip_load_category_base' ) ):
/**
* Enables a custom or no category base, if the site wants to use one that's not the WP.com default (/category/)
*
* Usage:
* wpcom_vip_load_category_base( '' );
* wpcom_vip_load_category_base( 'section' );
*
@Viper007Bond
Viper007Bond / whatissoslow.php
Last active Apr 24, 2019
WordPress: Times how long it takes each filter and action to run and displays results at the end of the page. Quick and dirty.
View whatissoslow.php
<?php
/**
* This little class records how long it takes each WordPress action or filter
* to execute which gives a good indicator of what hooks are being slow.
* You can then debug those hooks to see what hooked functions are causing problems.
*
* This class does NOT time the core WordPress code that is being run between hooks.
* You could use similar code to this that doesn't have an end processor to do that.
*
View gist:4717304
<?php
$my_query = new WP_Query( array(
'category__in' => array( 1, 2, 3 ),
'posts_per_page' => 10,
) );
View gist:4576706
<?php
add_action( 'plugins_loaded', 'tomnelseon_remove_birchschedule_hook' );
function tomnelseon_remove_birchschedule_hook() {
global $birchschedule;
remove_action( 'wp_ajax_birs_get_avaliable_time', array( $birchschedule->shortcode, 'ajax_get_avaliable_time' ) );
}
View gist:4342357
<?php
class WP_Widget_Text_HTML_In_Title extends WP_Widget {
function __construct() {
$widget_ops = array( 'classname' => 'widget_text_html_in_title', 'description' => 'Arbitrary text or HTML. Allows HTML in title field.' );
$control_ops = array( 'width' => 400, 'height' => 350 );
parent::__construct( 'text-html-in-title', 'Text (Allows HTML In Title)', $widget_ops, $control_ops );
}
View gist:4158778
<?php
$current_category = get_queried_object();
if ( $current_category->category_parent ) {
$parent_category = get_category( $current_category->category_parent );
$parent = $parent_category->name;
}
@Viper007Bond
Viper007Bond / gist:4153141
Created Nov 27, 2012
Auto-play YouTube embeds
View gist:4153141
<?php
add_filter( 'embed_oembed_html', 'blogsuccessjrnl_youtube_autoplay', 10, 4 );
function blogsuccessjrnl_youtube_autoplay( $html, $url, $attr, $post_ID ) {
// Abort if not in a single-post view. You don't want these auto-playing on you homepage.
if ( ! is_singular() )
return $html;
You can’t perform that action at this time.