Skip to content

Instantly share code, notes, and snippets.

@nathanrice
nathanrice / modular-stylesheets.php
Last active April 11, 2020 14:36
A simple proof-of-concept for modularizing the CSS for each block, and linking it "just in time".
<?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 June 20, 2016 14:44
Account for a desired 0 characters in content limit
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 January 6, 2016 16:41
Add back blogPosting Schema to Genesis sites
<?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 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 / 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 / functions.php
Created August 31, 2015 14:59
Remove entry meta for post types
<?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 16:34
Style new Genesis Accessibility output
/* ## 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 16:33
Enable Genesis Accessibility
//* Add Accessibility support
add_theme_support( 'genesis-accessibility', array( 'headings', 'drop-down-menu', 'search-form', 'skip-links' ) );
<?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 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',