Skip to content

Instantly share code, notes, and snippets.

View paulgibbs's full-sized avatar

Paul Wong-Gibbs paulgibbs

View GitHub Profile
jQuery('h1.widget-title').each(function(i) {
var new_heading = jQuery('<h3></h3>').append(jQuery(this).contents());
new_heading.attr('id', jQuery(this).attr('id'));
new_heading.attr('class', jQuery(this).attr('class'));
jQuery(this).replaceWith(new_heading);
})
jQuery('body.home #content h1.entry-title').each(function(i) {
var new_heading = jQuery('<h2></h2>').append(jQuery(this).contents());
new_heading.attr('id', jQuery(this).attr('id'));
Object Caching: APC / Memcached
Page Caching: Batcache
APC: http://wordpress.org/extend/plugins/apc/
Memcached: http://wordpress.org/extend/plugins/memcached/
Batcache: http://wordpress.org/extend/plugins/batcache/
Remember, these require server-side components or libraries; ask your host for advice before installing these plugins if you're not sure.
<?php
require_once getenv( 'WP_TESTS_DIR' ) . '/includes/functions.php';
function _install_and_load_liveblog() {
require dirname( __FILE__ ) . '/../liveblog.php';
}
tests_add_filter( 'muplugins_loaded', '_install_and_load_liveblog' );
require getenv( 'WP_TESTS_DIR' ) . '/includes/bootstrap.php';
@paulgibbs
paulgibbs / gist:5394388
Last active December 16, 2015 06:49
Change WordPress RSS feed output (i.e. exclude a category)
<?php
function pg_change_rss_query( $query ) {
if ( ! $query->is_feed )
return $query;
// Excludes posts in the staff category from the current feed
$query->set( 'category_name', 'staff' );
return $query;
}
@paulgibbs
paulgibbs / gist:5561643
Last active December 17, 2015 05:59
woocommerce taxonomy fix
Index: woocommerce-core-functions.php
===================================================================
--- woocommerce-core-functions.php (revision 711539)
+++ woocommerce-core-functions.php (working copy)
@@ -1425,6 +1425,9 @@
function woocommerce_terms_clauses( $clauses, $taxonomies, $args ) {
global $wpdb, $woocommerce;
+ // If we're not filtering a query for the product_cat taxonomy, bail out
+ if ( ! in_array( 'product_cat', $taxonomies ) ) return $clauses;
<?php
// Not tested, but it should work
function pg_adjust_main_query( $query ) {
/**
* If we're not on the blog posts index page,
* or if we're not modifying the main query,
* then bail out.
*/
<?php
function pg_config_achievement_post_type( $settings ) {
$settings['menu_icon'] = ''; // url here
return $settings;
}
add_filter( 'dpa_register_post_type_achievement', 'pg_config_achievement_post_type' );
@paulgibbs
paulgibbs / gist:5630455
Created May 22, 2013 20:02
How to load a custom extension for the Achievements for WordPress plugin
<?php
function pg_init_custom_extension() {
achievements()->extensions->your_extension = new Your_DPA_Extension_Class;
}
add_action( 'dpa_ready', 'pg_init_custom_extension' );
<?php $query = new WP_Query( array( 'posts_per_page' => 100, 'fields' => 'ids' ) ); ?>
<?php if ( $query->have_posts() ) :
$post_ids = $query->posts;
shuffle( $post_ids );
$post_ids = array_splice( $post_ids, 0, 12 );
foreach ( $post_ids as $post_id ) :
$post = get_post( $post_id );
setup_postdata( $post );
?>
<?php
// *****************************************************************************************
// Hi! These functions are early versions and might have bugs or not work properly, so YMMV.
// *****************************************************************************************
/**
* Prints the current function's return type and description. Template tag function for the function post type.
*
* @return string
*/