Skip to content

Instantly share code, notes, and snippets.

@nickdavis
nickdavis / functions.php
Created March 13, 2018 22:22
Get a WordPress menu from a specific menu location
<?php
/**
* Returns the menu object associated with a particular menu location.
*
* You could then get the slug of the menu, for example, via
* $menu_object->slug (or whatever variable you saved the menu object as).
*
* @param string $location_slug
*
@nickdavis
nickdavis / single.php
Created December 12, 2017 20:56
Show manual excerpt (only) if set in WordPress
<?php if ( has_excerpt() ) : ?>
<span><?= get_the_excerpt(); ?></span>
<?php endif; ?>
@nickdavis
nickdavis / acf-rules.php
Created May 2, 2017 06:42
(No longer) used Advanced Custom Field custom location rules for a client project, that might be useful for something else in future (props: Bill Erickson, as usual)
<?php
/**
* Register conditional locaton rules for Advanced Custom Fields
*
* @package ${NAMESPACE}.
* @since 1.0.0
* @author iamnickdavis
* @link http://iamnickdavis.com
* @license GNU General Public License 2.0+
*/
@nickdavis
nickdavis / pricing-table-five-columns.html
Created April 27, 2017 08:53
Five column example of Pricing Table for Kickstart Pro WordPress theme
<div class="pricing-table">
<div class="pricing-column one-fifth first">
<div class="pricing-content">
<h4>Start Right</h4>
<p>A wonderful piece of kit.</p>
<ul>
<li>Two Pens</li>
<li>A Ruler</li>
<li>A Notepad & more</li>
@nickdavis
nickdavis / pricing-table-four-columns.html
Last active April 27, 2017 08:51
Four column example of Pricing Table for Kickstart Pro WordPress theme
<div class="pricing-table">
<div class="pricing-column one-fourth first">
<div class="pricing-content">
<h4>Start Right</h4>
<p>A wonderful piece of kit.</p>
<ul>
<li>Two Pens</li>
<li>A Ruler</li>
<li>A Notepad & more</li>
@nickdavis
nickdavis / .gitmodules
Last active April 17, 2017 05:49
Sample .gitmodules file (tested and working with WP Engine git push, as long as .gitmodules is included in .gitignore)
[submodule "vendor/library-name"]
path = vendor/library-name
url = https://github.com/nickdavis/library-name
[submodule "vendor/library-name-2"]
path = vendor/library-name-2
url = https://github.com/nickdavis/library-name-2
@nickdavis
nickdavis / .gitignore
Created April 17, 2017 05:42
Starter .gitignore for new WordPress projects (based on https://www.billerickson.net/code/sample-gitignore/)
# Ignore everything #
**
!vendor/
vendor/**
!wp-content/
wp-content/**
!wp-content/themes/
!wp-content/plugins/
wp-content/themes/**
wp-content/plugins/**
<nav itemscope="" itemtype="http://schema.org/SiteNavigationElement" aria-label="Main navigation">
<ul class="menu">
<li class="menu-item"><a href="#" itemprop="url"><span itemprop="name">Left Item #1</span></a></li>
<li class="menu-item"><a href="#" itemprop="url"><span itemprop="name">Left Item #2</span></a></li>
<li class="menu-item"><a href="#" itemprop="url"><span itemprop="name">Left Item #3</span></a></li>
<li class="menu-item"><a href="#" itemprop="url"><span itemprop="name">Left Item #4</span></a></li>
<li class="menu-item"><a href="#" itemprop="url"><span itemprop="name">Left Item #5</span></a></li>
<li class="menu-item right"><a href="#" itemprop="url"><span itemprop="name">Right Item #1</span></a></li>
<li class="menu-item right"><a href="#" itemprop="url"><span itemprop="name">Right Item #1</span></a></li>
</ul>
@nickdavis
nickdavis / selling-benefits.html
Created March 13, 2017 19:47
Sample content for the 'Selling Benefits' text widget used in Home Row #6 of the Kickstart Pro theme demo (https://demo.leanthemes.co/kickstart/)
<p>Chris Guillebeau in "The $100 Startup" writes that people really care about<br/>having more of: <strong>Love</strong>, <strong>Money</strong>, <strong>Acceptance</strong> and <strong>Free Time</strong>.</p>
<ul class="featured">
<li>Saves you time</li>
<li>Makes you feel part of the community</li>
<li>Saves you money</li>
</ul>
@nickdavis
nickdavis / functions.php
Last active March 12, 2017 14:25
Find out the current capabilities of the contributor user role (NB. the ddd() function requires Kint to be installed)
<?php
add_action( 'init', 'check_contributor_capabilities', 0 );
function check_contributor_capabilities() {
ddd( get_role( 'contributor' ) );
}