Skip to content

Instantly share code, notes, and snippets.

@tjhole
tjhole / WORDPRESS: Enqueue only for template X
Created December 3, 2013 11:51
WORDPRESS: Enqueue only for template X
if ( is_page( 'page-template-page-landing-php' ) ) {
wp_enqueue_script( 'video' );
}
@tjhole
tjhole / PHP: Lastfm - months top artists
Created December 3, 2013 12:37
PHP: Lastfm - months top artists
This month we have been listening to
<?php
$username = 'tomhole1986';
$itemCount = 5;
$month = 1;
$scrobbler_url = "http://ws.audioscrobbler.com/2.0/user/" . $username . "/topartists.xml?period=" . $month . "month&limit=" . $itemCount . "";
$scrobbler_cache_file = 'scrobbler_' . $username . '_data.cache';
@tjhole
tjhole / WORDPRESS: Get And Cache Vimeo Thumbnails
Created December 5, 2013 13:07
WORDPRESS: Get And Cache Vimeo Thumbnails
// Get And Cache Vimeo Thumbnails
function get_vimeo_thumb($id, $size = 'thumbnail_small')
{
if(get_transient('vimeo_' . $size . '_' . $id))
{
$thumb_image = get_transient('vimeo_' . $size . '_' . $id);
}
else
{
$json = json_decode( file_get_contents( "http://vimeo.com/api/v2/video/" . $id . ".json" ) );
@tjhole
tjhole / CSS: Perfect Full Page Background
Created December 7, 2013 15:43
CSS: Perfect Full Page Background
background-position: center center;
background-repeat: no-repeat;
background-attachment: fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
@tjhole
tjhole / WORDPRESS: Function Stop Hyperlinking Images
Created December 9, 2013 12:51
WORDPRESS: Function Stop Hyperlinking Images
function rkv_imagelink_setup() {
$image_set = get_option( 'image_default_link_type' );
if ($image_set !== 'none') {
update_option('image_default_link_type', 'none');
}
}
add_action('admin_init', 'rkv_imagelink_setup', 10);
@tjhole
tjhole / JQUERY: Add non-breaking space to titles to prevent widows
Created December 10, 2013 13:41
JQUERY: Add non-breaking space to titles to prevent widows
$structure(document).ready(widow);
function widow(){
$structure("h1,h2,h3,h4,h5").each(function() {
var wordArray = $structure(this).text().split(" ");
var finalTitle = "";
for (i=0;i<=wordArray.length-1;i++) {
finalTitle += wordArray[i];
if (i == (wordArray.length-2)) {
@tjhole
tjhole / CSS: Smooth Font
Created December 10, 2013 17:17
CSS: Smooth Font
-webkit-font-smoothing: antialiased;
text-shadow: 1px 1px 1px rgba(0,0,0,0.004);
@tjhole
tjhole / ACF: Flexible Content
Created December 12, 2013 17:46
ACF: Flexible Content ACF: Flexible Content
<?php
/*
* Loop through a Flexible Content field and display it's content with different views for different layouts
*/
while(has_sub_field("content")): ?>
<?php if(get_row_layout() == "paragraph"): // layout: Content ?>
@tjhole
tjhole / ACF: Location Get Lat Long
Created December 12, 2013 18:40
ACF: Location Get Lat Long
<?php
$location = get_field('location');
if( !empty($location) ):
?>
<?php echo $location['lat']; ?>
<?php echo $location['lng']; ?>">
<?php endif; ?>
@tjhole
tjhole / ACF: Location > Static Google Map
Created December 12, 2013 18:48
ACF: Location > Static Google Map
<?php
$location = get_sub_field('location');
if( !empty($location) ):
?>
<img src="http://maps.googleapis.com/maps/api/staticmap?center=<?php echo $location['lat']; ?>,<?php echo $location['lng']; ?>&zoom=15&format=png&sensor=false&size=640x480&maptype=roadmap&visual_refresh=true&style=visibility:off&style=feature:road|element:geometry|visibility:simplified|color:0xefecec&style=feature:landscape|element:geometry|visibility:simplified|color:0xffffff&style=element:labels|visibility:on&markers=color:black|<?php echo $location['lat']; ?>,<?php echo $location['lng']; ?>"/>
<?php endif; ?>