Skip to content

Instantly share code, notes, and snippets.

View mattradford's full-sized avatar
👋

Matt Radford mattradford

👋
View GitHub Profile
@mattradford
mattradford / 0_reuse_code.js
Last active August 29, 2015 14:06
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
function mattrad_remove_script_version( $src ){
return remove_query_arg( 'ver', $src );
}
add_filter( 'script_loader_src', 'mattrad_remove_script_version' );
add_filter( 'style_loader_src', 'mattrad_remove_script_version' );
@mattradford
mattradford / email_anti_spam.php
Last active August 29, 2015 14:06
Antispam encoded email
<?php _e('Email us','roots'); ?>: <?php $tend_email = get_field('email_address', 'options'); ?><a href="mailto:<?php echo antispambot( $tend_email, 1 ); ?>"><?php echo antispambot( $tend_email, 0 ); ?></a>
@mattradford
mattradford / gravity_forms_uk.php
Last active August 29, 2015 14:06
Gravity forms UK addresses
// Gravity forms UK Address. Stick it in your functions.php
function uk_address($address_types, $form_id) {
$address_types["uk"] = array(
"label" => "UK & Ireland",
"country" => "UK",
"zip_label" => "Postcode",
"state_label" => "County",
"states" => array("Aberdeenshire"=>"Aberdeenshire","Angus/Forfarshire"=>"Angus/Forfarshire","Argyllshire"=>"Argyllshire","Ayrshire"=>"Ayrshire","Banffshire"=>"Banffshire","Bedfordshire"=>"Bedfordshire","Berkshire"=>"Berkshire",
"Berwickshire"=>"Berwickshire","Blaenau Gwent"=>"Blaenau Gwent","Bridgend"=>"Bridgend","Buckinghamshire"=>"Buckinghamshire","Buteshire"=>"Buteshire","Caerphilly"=>"Caerphilly","Caithness"=>"Caithness",
@mattradford
mattradford / child_pages_loop.php
Created September 24, 2014 16:03
Child pages loop
<?php
$args = array(
'post_parent' => $post->ID,
'post_type' => 'page',
'orderby' => 'menu_order'
);
$child_query = new WP_Query( $args );
?>
@mattradford
mattradford / wp_get_posts.php
Created September 25, 2014 14:13
Get last 5 posts
// Don't use get_archives. It's deprecated.
<?php wp_get_archives( array( 'type' => 'postbypost', 'limit' => 5 ) ); ?>
@mattradford
mattradford / post_thumb_bg.php
Created September 30, 2014 09:30
post_thumbnail as background image
<?php
$image_src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array( 5600,1000 ), false, '' );
?>
<div class="post-thumbnail" style="background-image: url('<?php echo $image_src[0]; ?>');">
@mattradford
mattradford / social_share.php
Last active August 29, 2015 14:07
Social icons with share code, without Javascript
<div class="social-icons">
<a class="icon-twitter" href="javascript:window.location=%22https://twitter.com/share?url=%22+encodeURIComponent(document.location)+%22&text=%22+encodeURIComponent(document.title)" title="<?php _e('Share on Twitter','roots'); ?>"></a>
<a class="icon-facebook" href="javascript:window.location=%22http://www.facebook.com/sharer.php?u=%22+encodeURIComponent(document.location)+%22&#38;t=%22+encodeURIComponent(document.title)" title="<?php _e('Share on Facebook','roots'); ?>"></a>
<a class="icon-linkedin" href="http://www.linkedin.com/shareArticle?mini=true&url=<?php if(is_home()){echo home_url();}else{the_permalink();} ?>" title="<?php _e('Share on LinkedIn','roots'); ?>"></a>
<a class="icon-google" href="https://plusone.google.com/_/+1/confirm?hl=en&url=<?php if(is_home()){echo home_url();}else{the_permalink();} ?>" title="<?php _e('Share on Google+','roots'); ?>"></a>
</div>
@mattradford
mattradford / post_siblings.php
Last active August 29, 2015 14:07
Get siblings of post. Remove . '&exclude=' . $post->ID to include current post.
<?php
// global $post; //not necessary if used in the loop
$parent_id = $post->post_parent;
if( $parent_id ) :
$siblings = get_pages( 'child_of=' . $parent_id . '&parent=' . $parent_id . '&exclude=' . $post->ID);
if( $siblings ) foreach( $siblings as $sibling ) :
//start of whatever you need to output//
echo $sibling->post_title;
echo get_the_post_thumbnail($sibling->ID,'medium');
//end of whatever you need to output//
@mattradford
mattradford / cpt_no_slug.php
Created October 15, 2014 22:32
Remove slug from CPT
// Remove slug from CPT
// Careful of collisions and permalink must be %postname%
// http://www.itsabhik.com/remove-custom-post-type-slug/
// There was an error in the code after $args array: , not ;
// See also http://colorlabsproject.com/tutorials/remove-slugs-custom-post-type-url/
function remove_cpt_slug( $post_link, $post, $leavename ) {
$args = array(
'public' => true,