Skip to content

Instantly share code, notes, and snippets.

@rezzz-dev
rezzz-dev / template-blankpage.php
Last active December 18, 2015 01:59
Snippet: WP: Blank Template
<?php
/*
Template Name: Blank Page
Template By : Jason Resnick
URL : http://rezzz.com
*/
?>
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
@rezzz-dev
rezzz-dev / gist:6292812
Created August 21, 2013 10:25
Snippet: WP Login-Logout Menu Item
function jr_add_loginout_navitem($items, $args ) {
if( $args->theme_location == 'header_nav' ) {
if ( !(is_user_logged_in()) ) {
$login_item = '<li class="nav-login"><a href="/login">Log In</a></li>';
}
else {
$login_item = '<li class="nav-login">'.wp_loginout($_SERVER['REQUEST_URI'], false).'</li>';
}
$items .= $login_item;
}
@rezzz-dev
rezzz-dev / gist:6379035
Created August 29, 2013 14:45
Snippet: WP Get Excerpt by ID
function get_excerpt_by_id($post_id, $n){
$the_post = get_post($post_id); //Gets post ID
$the_excerpt = $the_post->post_content; //Gets post_content to be used as a basis for the excerpt
$excerpt_length = $n; //Sets excerpt length by word count
$the_excerpt = strip_tags(strip_shortcodes($the_excerpt)); //Strips tags and images
$words = explode(' ', $the_excerpt, $excerpt_length + 1);
if(count($words) > $excerpt_length) :
array_pop($words);
// array_push($words, '…');
@rezzz-dev
rezzz-dev / gist:6713387
Created September 26, 2013 12:21
Snippet: WP: List Custom Post Type Group By Taxonomy
<?php
$attractions = get_terms('attraction', array("fields" => "names"));
for ( $myterm = 0; $myterm < count($attractions); $myterm++) { ?>
<h3><?php echo $attractions[$myterm]; ?>:</h3>
<div class="taxonomy_group">
<?php $loop = new WP_Query(array('attraction' => $attractions[$myterm]));
while ( $loop->have_posts() ) : $loop->the_post();
get_template_part( 'content', 'things-to-do' );
endwhile; ?>
</div>
@rezzz-dev
rezzz-dev / style.css
Created January 10, 2015 16:44
Child Theme style.css Template
/*
Theme Name: <theme name>
Theme URI: http://rezzz.com
Author: Jason Resnick
Author URI: http://rezzz.com/jason-resnick/
Description: A Child theme off of <parent theme> built for the <name of> website
Version: 1.0
Template: <parent theme directory name>
Text Domain: <name of>-child
*/
@rezzz-dev
rezzz-dev / functions.php
Last active August 29, 2015 14:13
Child Theme functions.php
<?php
/* <name of> child theme */
// Faster than @import
add_action( 'wp_enqueue_scripts', 'my_child_theme_scripts' );
function my_child_theme_scripts() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
@rezzz-dev
rezzz-dev / pmp-mulitple-checkout-boxes.php
Last active March 21, 2018 16:31
multiple-checkout-boxes.php
<?php
/*
Plugin Name: Register Helper Example
Plugin URI: http://www.paidmembershipspro.com/wp/pmpro-customizations/
Description: Register Helper Initialization Example
Version: .1
Author: Stranger Studios
Author URI: http://www.strangerstudios.com
*/
//we have to put everything in a function called on init, so we are sure Register Helper is loaded
@rezzz-dev
rezzz-dev / CLI.sh
Created January 7, 2016 14:58
PHP Code Sniffer with WordPress Coding Standards and Atom
#Install PHP CodeSniffer
brew install homebrew/php/php-code-sniffer #if using Homebrew
git clone https://github.com/squizlabs/PHP_CodeSniffer.git phpcs #if you want to do it directly
#Install WordPress Coding Standards
git clone -b master https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git wpcs
#Add WordPress standards to PHPCS config
phpcs -i #shows the libraries installed
phpcs --config-set installed_paths <path to dir that you cloned>/wpcs
@rezzz-dev
rezzz-dev / functions.php
Last active January 20, 2016 14:35
Filter Recent Posts Widget by current categories, but excluding current post
<?php
/*
* Filter Recent Posts based around the categories of the post being displayed
*/
function rez_widget_posts_args( $args ) {
if ( is_single() ) { // Only want to appear on blog posts.
$post = get_queried_object();
$categories = wp_get_post_categories( $post->ID );
$cats = implode( ',',$categories );
@rezzz-dev
rezzz-dev / functions.php
Created February 25, 2016 13:29
Re-order WooCommerce Checkout Fields
<?php
/*
* Re-order Checkout Fields
*/
add_filter( 'woocommerce_checkout_fields', 'rez_move_checkout_fields' );
function rez_move_checkout_fields( $fields ) {
$fields2['billing']['billing_email'] = $fields['billing']['billing_email'];