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
<?php
$my_query = new WP_Query( array(
'category__in' => array( 1, 2, 3 ),
'posts_per_page' => 10,
) );
@Viper007Bond
Viper007Bond / whatissoslow.php
Last active March 19, 2025 10:22
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
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 / 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;
}
@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 / 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';
} );