Skip to content

Instantly share code, notes, and snippets.

View mfields's full-sized avatar

Michael Fields mfields

  • Portland, Oregon, USA
View GitHub Profile
<?php
/**
* @package Portfolio Press
*/
/**
* Helper function to get options set by the Options Framework plugin
*/
if ( !function_exists( 'of_get_option' ) ) :
function of_get_option( $name, $default = false ) {
@mfields
mfields / customizer.js
Created February 21, 2014 19:00
Portfolio Press: customizer.js
( function( $ ) {
var $title = $( '#site-title a' ),
$tagline = $( '#site-description' ),
$branding = $( '#branding' );
/* Title Text */
wp.customize( 'blogname', function( value ) {
value.bind( function( to ) {
$title.text( to );
} );
@mfields
mfields / gist:5945426
Created July 7, 2013 23:59
comment-reply script enqueue
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
@mfields
mfields / gist:5607666
Created May 19, 2013 13:43
Off-screen canvas rendering of a gradient
( function () {
var canvas = document.getElementById( 'stage' ),
context = stage.getContext( '2d' ),
gradient = document.createElement( 'canvas' );;
( function ( size, renderFunction ) {
var gc = gradient.getContext( '2d' ),
size = 100,
half = size / 2,
/**
* Simple animation loop with start and stop controls.
*/
var animationFrameId;
/**
* Animation Loop.
*
* @uses animationFrameId
<h2>Fullsize Images Tests</h2>
<h3>Captioned (Unlinked)</h3>
[caption id="attachment_2127" align="alignnone" width="1024"]<img class="size-full wp-image-2127" title="Red flower" alt="" src="http://wpthemetestdata.files.wordpress.com/2008/09/test-image-landscape-900.jpg" width="1024" height="685" /> Full - None[/caption]
[caption id="attachment_2127" align="alignleft" width="1024"]<img class="size-full wp-image-2127" title="Red flower" alt="" src="http://wpthemetestdata.files.wordpress.com/2008/09/test-image-landscape-900.jpg" width="1024" height="685" /> Full - Left[/caption]
[caption id="attachment_2127" align="aligncenter" width="1024"]<img class="size-full wp-image-2127" title="Red flower" alt="" src="http://wpthemetestdata.files.wordpress.com/2008/09/test-image-landscape-900.jpg" width="1024" height="685" /> Full - Center[/caption]
[caption id="attachment_2127" align="alignright" width="1024"]<img class="size-full wp-image-2127" title="Red flower" alt="" src="http://wpthemetestdata.files.wordpress.com/
// It's best to escape the whole url:
// This will also convert the ampersand to an entity.
// esc_url() is for printing to the screen.
// esc_url_raw() is for database saves.
echo '<a href="' . esc_url( 'https://twitter.com/share?url=' . $pxjn_share_url . '&text=' . $pxjn_share_text ) . '"><span class="share tweetthis">Tweet This</span></a>';
@mfields
mfields / gist:4963583
Created February 15, 2013 21:11
A very good way to display comments_popup_link() in a WordPress theme.
<?php if ( ! post_password_required() && ( comments_open() || '0' != get_comments_number() ) ) : ?>
<span class="comments-link"><?php comments_popup_link(
__( 'Leave a comment', 'mytheme' ),
__( '1 Comment', 'mytheme' ),
__( '% Comments', 'mytheme' )
); ?></span>
<?php endif; ?>\
@mfields
mfields / example.php
Created February 1, 2013 01:15
Illustrate how to check the value of ```post__in``` before it is used to construct a new ```WP_Query``` object.
<?php
$my_posts = false;
$my_post_ids = mytheme_get_special_post_ids();
if ( ! empty( $my_post_ids ) ) {
$my_posts = new WP_Query( array(
'post__in' => $my_post_ids,
'post_status' => 'publish',
'posts_per_page' => 10,
@mfields
mfields / theme-options.php
Created January 31, 2013 01:12
Sample theme options page for WordPress Themes.
<?php
/**
* _s Theme Options
*
* @package _s
* @since _s 1.0
*/
/**
* Register the form setting for our _s_options array.