Skip to content

Instantly share code, notes, and snippets.

@nathanrice
nathanrice / gist:9399581
Created March 6, 2014 21:03
Debug rogue redirects in WordPress
<?php
//* Debug redirect
add_filter( 'wp_redirect', function( $location ) {
if ( home_url() == $location ) {
print_r( debug_backtrace() );
return false;
}
@nathanrice
nathanrice / fruits.php
Created March 7, 2014 17:03
Example of unset not working properly
<?php
class Fruit_List {
private $fruit = array();
function __construct() {
$this->add_fruit( array(
1 => 'apple',
2 => 'orange',
<?php
//* Do NOT include the opening php tag
add_filter( 'stylesheet_uri', 'custom_replace_default_style_sheet', 10, 2 );
/**
* Replace main theme style sheet with custom one if viewing post in a particular category.
*
* Note: Replace X with the category ID you want to target.
*/
function custom_replace_default_style_sheet( $stylesheet, $stylesheet_dir ) {
@nathanrice
nathanrice / git-svn.txt
Created October 6, 2015 19:55
Sync Github repo with WordPress.org repo
svn co url-of-svn-repo
cd trunk
rm -rvf * *.* .*
git clone git-repo.git
copy files:
package.json
Gruntfile.js
.gitignore
.gitattributes
@nathanrice
nathanrice / feed.php
Last active October 13, 2015 17:46
Custom fetch_feed() function
<?php
function cb_fetch_feed( $url ) {
require_once( ABSPATH . WPINC . '/class-feed.php' );
$feed = new SimplePie();
$feed->set_sanitize_class( 'WP_SimplePie_Sanitize_KSES' );
// We must manually overwrite $feed->sanitize because SimplePie's
// constructor sets it before we have a chance to set the sanitization class
@nathanrice
nathanrice / jetpack-open-graph-tags.php
Last active December 12, 2015 00:28
Use Genesis Doctitle and Meta Description with Jetpack's Open Graph tags on entry pages.
<?php
add_filter( 'jetpack_open_graph_tags', 'nr_jetpack_open_graph_tags_filter' );
/**
* Filter open graph tags to use Genesis doctitle and meta description instead.
*
* @author Nathan Rice
* @link https://gist.github.com/4683845
*/
function nr_jetpack_open_graph_tags_filter( $tags ) {
<?php
//** Redirect if not logged in
if ( ! is_user_logged_in() && 'wp-login.php' !== $pagenow ) {
wp_redirect( wp_login_url() );
exit;
}
@nathanrice
nathanrice / single-recipe.php
Created May 16, 2013 14:36
A sample single template for a Recipe CPT with Genesis
<?php
/**
* This file controls the single view of the Recipe CPT
*/
/**
* This is where you would put your custom mods. Just hook them (or unhook) to the proper location.
*/
genesis(); //* <-- Just make sure this is at the END of the file.
@nathanrice
nathanrice / .profile
Last active December 17, 2015 22:09
Convert GitHub issue into a Pull Request
# Replace [username] with your GitHub username (in both places).
# Replace [project]/[repository] with the project and repository where the issue resides.
# Replace [base] with the destination branch you wish to PR to (usually master or develop)
# And obviously, don't leave the [] brackets in there.
# Usage:
# @git-pr 999 features/999
@nathanrice
nathanrice / functions.php
Created August 2, 2013 20:05
Unit test for HTML5 support in WordPress 3.6
<?php
//* Only turn on HTML5 for comment list
add_theme_support( 'html5', array( 'comment-list' ) );