Skip to content

Instantly share code, notes, and snippets.

View krogsgard's full-sized avatar

Brian Krogsgard krogsgard

View GitHub Profile
@krogsgard
krogsgard / register_rest_fields.php
Last active September 1, 2016 22:01
Add meta data for a CPT to the REST response. `wp-json/wp/v2/poststatus_partners?_embed`
<?php
add_action( 'rest_api_init', function() {
register_rest_field(
array( 'poststatus_partners' ),
'partner_meta',
array(
'get_callback' => 'poststatus_get_restable_field_values_for_partner_meta',
'update_callback' => 'poststatus_update_restable_field_values_for_partner_meta',
'schema' => null,
@krogsgard
krogsgard / enqueue-scripts.php
Created May 15, 2012 02:23
Sample enqueue scripts action and function
<?php
/*
* WordPress Sample function and action
* for loading scripts in themes
*/
// Let's hook in our function with the javascript files with the wp_enqueue_scripts hook
add_action( 'wp_enqueue_scripts', 'wpcandy_load_javascript_files' );
@krogsgard
krogsgard / meta-box-control.php
Created February 4, 2013 16:19
gist to lower priority of WP SEO metabox
<?php
add_filter('wpseo_metabox_prio','krogs_lower_wpseo_metabox', 10 );
function krogs_lower_wpseo_metabox( $priority ) {
$priority = 'low';
return $priority;
@krogsgard
krogsgard / gitignore.txt
Created February 29, 2016 20:10
Having all plugins in Git is a pain. It makes life easier to manage just the plugins I personally maintain in Git.
.DS_Store
node_modules
.sass-cache
uploads
debug.log
.css.map
themes/*
!themes/poststatus/
@krogsgard
krogsgard / template-file.php
Last active January 29, 2016 17:21
Stuff for wrangling Jetpack. End result is along these lines: https://cldup.com/8x050WNF_L.png
<?php echo krogs_output_related_posts(); ?>
@krogsgard
krogsgard / rest-resources.txt
Last active January 13, 2016 14:10
I'll work to collect and add to this. Might be good stuff for javascriptdeeply.com :) I've covered loads of REST API stuff in my newsletter (poststatus.com/club), but don't have a definitive list anywhere that's more evergreen. Let's do that!
Basic docs: http://v2.wp-api.org/
Extending (includes philosophy): http://v2.wp-api.org/extending/adding/
Scott Bolinger has good posts: http://scottbolinger.com/category/wp-api/
And (mostly corresponding) gists: https://gist.github.com/scottopolis/
Good series: https://deliciousbrains.com/tag/wp-rest-api/
Nice eBook intro: https://wpengine.com/blog/wordpress-rest-api-free-ebook/
@krogsgard
krogsgard / old-underscores-toggle.js
Created August 30, 2013 04:34
This is a toggle method previously used by the _s theme that utilizes jQuery and a specific browserWidth trigger.
/**
* Handles toggling the main navigation menu for small screens.
*/
jQuery( document ).ready( function( $ ) {
var $masthead = $( '#masthead' ),
timeout = false;
$.fn.smallMenu = function() {
$masthead.find( '.site-navigation' ).removeClass( 'main-navigation' ).addClass( 'main-small-navigation' );
$masthead.find( '.site-navigation h1' ).removeClass( 'assistive-text' ).addClass( 'menu-toggle' );
<?php
function poststatus_get_love_it() {
if ( 'post' == get_post_type() ) {
$love_output = lip_love_it_link( $post_id = get_the_ID(), $link_text = ' <div class="genericon genericon-collapse"></div> ', $already_loved = '', $echo = false );
return $love_output;
}
@krogsgard
krogsgard / wp-query-doing-it-wrong.php
Last active December 19, 2015 06:59
Don't copy this. It's just a sample of doing it wrong.
<?php
/*
* WP_Query doing_it_wrong
*
* i'm commenting this so you don't copy / paste this fail sauce
*/
$original_query = $wp_query; // YUDOTHAT???
$wp_query = null; // Oh, man