Skip to content

Instantly share code, notes, and snippets.

View mfields's full-sized avatar

Michael Fields mfields

  • Portland, Oregon, USA
View GitHub Profile
@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.
@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,
$template_name = 'my-custom-template.php';
$path = locate_template( $template_name );
if ( empty( $path ) )
$path = dirname( __FILE__ ) . '/' . $template_name;
@mfields
mfields / gist:4014915
Created November 5, 2012 02:09
Theme Review of Black Zebra for Extend.
Need to be fixed for inclusion
------------------------------
* The function ```register_sidebar()``` needs to be called during the ```widgets_init``` hook. Please refer to Twenty Twelve's function.php file for an example of how to do this.
* The template tag ```the_title()``` may not be printed inside an attribute. Please use ```the_title_attribute()``` instead. This code was found in line 14 of 404.php, line 11 of archive.php, line 9 of header.php, line 11 of index.php, line 11 of page.php, line 13 of search.php, and line 11 of single.php.
* Please move the function definition for ```blackzebra_custom_styles()``` into functions.php.
* Please remove the additional enqueue for a child theme from ```blackzebra_custom_styles()```. It is best to let the child theme make this decision.
* Please remove the favicon from header.php.
* Please remove the Atom Link from header.php. This functionality should be taken care of by ```add_theme_support( 'automatic-feed-links' )```
* Table headings are the same color as the