Skip to content

Instantly share code, notes, and snippets.

@TheHeat
TheHeat / Add Soundcloud oEmbed to WordPress
Created August 2, 2012 00:24
Paste this into your functions.php to add Soundcloud oEmbed support to a WordPress theme.
wp_oembed_add_provider( 'http://soundcloud.com/*', 'http://soundcloud.com/oembed' );
@TheHeat
TheHeat / span_copyright.php
Created December 6, 2012 13:23
WordPress theme conditional copyright function.
@TheHeat
TheHeat / gist:4573126
Created January 19, 2013 15:20
In Wordpress, if more than a single term exists within a given taxonomy, display the terms as links to their archives.
<?php $terms = get_terms("taxonomy_name");
$count = count($terms);
if ( $count > 1 ): foreach ( $terms as $term ): ?>
<a href="<?php echo get_bloginfo('url') . '/taxonomy_slug/' . $term->slug ?>"><?php echo $term->name ?></a>
<?php endforeach; endif; ?>
@TheHeat
TheHeat / auto_h_level.php
Created March 22, 2013 16:32
In WordPress display the title and content of an hierarchical post-type with h tags based on the level of the hierarchy. Top level posts have <h1> titles, their children <h2> and so on. I used this to create a Terms and Conditions page based on a hierarchical custom-post-type. I've also included the post slug as the section ID for better navigat…
<?php $args = array(
'sort_order' => 'ASC',
'sort_column' => 'menu_order',
'hierarchical' => true,
'post_type' => 'post_type',
'post_status' => 'publish'
);
$post_type = get_pages($args);
foreach ($post_type as $post_object):
@TheHeat
TheHeat / get_video_image.php
Created March 30, 2013 09:04
In WordPress, if a featured image isn't set. check for a custom field called 'video' and if there's a url in there from either Vimeo or YouTube (including youtu.be shortened links) nab the thumbnail.
<?php
// Check for a featured image with get_the_image by Justin Tadlcok http://themehybrid.com
// if one is not found check for a custom field called video
// if there is a custom field called video and it has an address from Vimeo or YouTube, grab the thumbnail
?>
<?php $thid = get_the_ID();
$vim_prefix = 'http://vimeo.com/';
$yt_prefix = 'http://www.youtube.com/watch?v=';
@TheHeat
TheHeat / business-hours.php
Last active December 16, 2015 11:09
Set default business opening hours as a multidimensional array. Allow for 2 types of exceptions (closed and bank holidays) then return the opening hours in a number of useful ways, including a JS powered "we are open/closed" thingy.
<?php
date_default_timezone_set('Europe/London');
// Define normal opening hours in nested arrays
$days = array(
'monday' => array('label' => 'Monday', 'open' => '09:30', 'close' => '22:00'),
'tuesday' => array('label' => 'Tuesday', 'open' => '09:30', 'close' => '22:00'),
'wednesday' => array('label' => 'Wednesday','open' => '09:30', 'close' => '22:00'),
@TheHeat
TheHeat / heat_twitter_card.php
Created April 24, 2013 18:41
Fire WordPress post info into a Twitter summary card.
function heat_twitter_card(){
$title = get_post_meta(get_queried_object_id(), 'Title', true);
$description = get_post_meta(get_queried_object_id(), 'Description', true);
$image = get_the_image(array('format'=>'array')); ?>
<!--Twitter Card-->
<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="@marcheatley">
@TheHeat
TheHeat / autopopulate.js
Last active December 17, 2015 19:09 — forked from mrcave/javascript.js
Retrieve querystring values from the uri, strip out encoded characters and add them to form fields with equivalent names. I'm using this to pre-populate a a generic contact form with dates and details based on which link is clicked.
jQuery(function ($) {
//grab the entire query string
var query = document.location.search.replace('?', '');
//extract each field/value pair
query = query.split('&');
//run through each pair
for (var i = 0; i < query.length; i++) {
@TheHeat
TheHeat / upcoming-events.php
Last active December 18, 2015 02:19 — forked from stephenharris/upcoming-events.php
Display a list of upcoming events with Event Organiser http://wp-event-organiser.com/ without repeating instances of recurring events.
/**
* Display a list of upcoming events with Event Organiser without repeating instances of recurring events
**/
//Get upcoming events for the next 6 months
$events = eo_get_events(array(
'event_start_after'=>'today',
'event_end_after' =>'today',
'event_start_before' => '+6 month',
@TheHeat
TheHeat / taxterm-title.php
Created February 11, 2014 15:21
WP taxonomy term archive title
if (is_tax() ) :
$single_tax_term = get_queried_object();
echo $single_tax_term->name;
endif;