Skip to content

Instantly share code, notes, and snippets.

Nathan Rice nathanrice

Block or report user

Report or block nathanrice

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
@nathanrice
nathanrice / modular-stylesheets.php
Last active May 31, 2019
A simple proof-of-concept for modularizing the CSS for each block, and linking it "just in time".
View modular-stylesheets.php
<?php
// this snippet requires PHP 5.3+
add_action( 'wp_enqueue_scripts', function() {
wp_register_style( 'atomic-blocks/ab-cta', '/path/to/atomic-blocks/css/ab-cta.css', array(), 1.0.0 );
} );
add_filter( 'render_block', function( $block_content, $block ) {
if ( 'atomic-blocks/ab-cta' === $block['blockName'] ) {
ob_start();
wp_print_styles( $block['blockName'] );
@nathanrice
nathanrice / formatting.php
Created Jun 20, 2016
Account for a desired 0 characters in content limit
View formatting.php
function genesis_truncate_phrase( $text, $max_characters ) {
if ( ! $max_characters ) {
return '';
}
$text = trim( $text );
if ( mb_strlen( $text ) > $max_characters ) {
@nathanrice
nathanrice / functions.php
Created Jan 6, 2016
Add back blogPosting Schema to Genesis sites
View functions.php
<?php
/*
Add back Schema.org/blogPosting microdata to post entries.
Replace all instances of "themedemo" with something unique to your site.
User input is required in the last function. Be sure to fill these fields in with your own information.
Instances where you need to fill in information will be marked with a comment that indicates so.
*/
@nathanrice
nathanrice / feed.php
Last active Oct 13, 2015
Custom fetch_feed() function
View feed.php
<?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 / git-svn.txt
Created Oct 6, 2015
Sync Github repo with WordPress.org repo
View git-svn.txt
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 / functions.php
Created Aug 31, 2015
Remove entry meta for post types
View functions.php
<?php
add_action( 'init', 'sample_remove_entry_meta', 11 );
/**
* Remove entry meta for post types
*
* @link https://gist.github.com/nathanrice/03a5871e5e5a27f22747
*/
function sample_remove_entry_meta() {
remove_post_type_support( 'post-type', 'genesis-entry-meta-before-content' );
@nathanrice
nathanrice / style.css
Created May 28, 2015
Style new Genesis Accessibility output
View style.css
/* ## Screen reader text
--------------------------------------------- */
.screen-reader-text,
.screen-reader-text span,
.screen-reader-shortcut {
position: absolute !important;
clip: rect(0, 0, 0, 0);
height: 1px;
width: 1px;
@nathanrice
nathanrice / functions.php
Created May 28, 2015
Enable Genesis Accessibility
View functions.php
//* Add Accessibility support
add_theme_support( 'genesis-accessibility', array( 'headings', 'drop-down-menu', 'search-form', 'skip-links' ) );
View functions.php
<?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 / fruits.php
Created Mar 7, 2014
Example of unset not working properly
View fruits.php
<?php
class Fruit_List {
private $fruit = array();
function __construct() {
$this->add_fruit( array(
1 => 'apple',
2 => 'orange',
You can’t perform that action at this time.