Skip to content

Instantly share code, notes, and snippets.

View soutar's full-sized avatar
🤖
automating things

John Soutar soutar

🤖
automating things
  • London, UK
  • 11:06 (UTC +01:00)
View GitHub Profile
@soutar
soutar / functions.php
Created May 20, 2014 12:23
Enqueue Font Awesome styles
<?php
function include_font_awesome() {
wp_enqueue_style('font_awesome', '//netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css');
}
/* When 'wp_enqueue_scripts' takes place, trigger this function */
add_action('wp_enqueue_scripts', 'include_font_awesome', 100);
@soutar
soutar / oo_shortcodes.php
Last active August 29, 2015 14:01
OO Shortcodes
<?php
class My_Shortcode extends Shortcode {
public function main($atts, $content) {
echo "This is a really easy way to add shortcodes!";
}
}
$My_Shortcode = new My_Shortcode;
$My_Shortcode->add();
@soutar
soutar / section_nav.php
Last active August 29, 2015 14:00
Quick infinite-depth subnav for WordPress
<?php
function cad_section_nav($title = true) {
global $post;
if (!is_object($post)) return;
$section = get_post_ancestor($post->ID);
$pages = get_pages(array(
'parent' => $section->ID
@soutar
soutar / get_ancestor.php
Created April 28, 2014 09:10
Return the ultimate ancestor of a post
<?php
/* Return the ultimate ancestor of a post */
function get_post_ancestor($postID) {
$post = get_post($postID);
if (!is_object($post)) return;
while ($post->post_parent != 0): $post = get_post($post->post_parent); endwhile;
return $post;
}