Skip to content

Instantly share code, notes, and snippets.

View Viper007Bond's full-sized avatar
😎
Writing Code

Alex Mills Viper007Bond

😎
Writing Code
View GitHub Profile
@Viper007Bond
Viper007Bond / functions.php
Created September 18, 2017 16:46
Change who can use Regenerate Thumbnails
<?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 March 28, 2015 21:19
Include pages in category archive pages
<?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 April 7, 2014 19:53
Default WordPress to use 4 column galleries
<?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;
}
<?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 October 29, 2023 14:23
WordPress: Times how long it takes each filter and action to run and displays results at the end of the page. Quick and dirty.
<?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.
*
<?php
$my_query = new WP_Query( array(
'category__in' => array( 1, 2, 3 ),
'posts_per_page' => 10,
) );
<?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' ) );
}
<?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 );
}
<?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 November 27, 2012 08:35
Auto-play YouTube embeds
<?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;