Skip to content

Instantly share code, notes, and snippets.

View krogsgard's full-sized avatar

Brian Krogsgard krogsgard

View GitHub Profile
@krogsgard
krogsgard / sample-functions-child-theme.php
Last active November 2, 2018 19:50
jQuery for handling toggle functionality with wp_localize_script ( small_menu_vars.size ) and WordPress.
<?php
/**
* krogs_child_theme_new_menu_size function.
*
*/
add_filter( 'krogs_theme_small_menu_size', 'krogs_child_theme_new_menu_size' );
function krogs_child_theme_new_menu_size( $size ) {
$size = 450;
@krogsgard
krogsgard / old-underscores-header-markup.php
Last active December 21, 2021 09:10
This is an example of the older small-menu handling with the part of the header and .js files for the _s theme that are relevant
<header id="masthead" class="site-header" role="banner">
<hgroup>
<h1 class="site-title"><a href="<?php echo home_url( '/' ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
<h2 class="site-description"><?php bloginfo( 'description' ); ?></h2>
</hgroup>
<nav role="navigation" class="site-navigation main-navigation">
<h1 class="assistive-text"><?php _e( 'Menu', '_s' ); ?></h1>
<div class="assistive-text skip-link"><a href="#content" title="<?php esc_attr_e( 'Skip to content', '_s' ); ?>"><?php _e( 'Skip to content', '_s' ); ?></a></div>
@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-the-right-way.php
Last active January 4, 2021 21:59
sample custom WP_Query the right way
<?php
/*
* WP_Query happy dance
*
* this is a sample WP_Query the right way
*/
$args = array (
'post_type' => 'post',
@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
<?php
add_action( 'pre_new_day', 'krogs_alter_new_day' );
/**
* krogs_alter_new_day function.
*
* @access public
* @param mixed $day
<?php
// add shopping cart thingy
function mystore_shopping_cart() {
global $woocommerce;
?>
<aside class="header-cart-info">
<a href="<?php echo $woocommerce->cart->get_cart_url(); ?>" title="View your shopping carts" class="cart-contents">
@krogsgard
krogsgard / featured-posts.php
Created March 27, 2013 16:37
Recent posts shortcode example. Inspired by Bill Erickson's excellent Display Posts shortcode.