Skip to content

Instantly share code, notes, and snippets.

View mattradford's full-sized avatar
👋

Matt Radford mattradford

👋
View GitHub Profile
@mattradford
mattradford / acf_get_directions.php
Last active February 16, 2023 12:08
ACF Get Directions map link
<?php
$location = get_field('map_location');
if ( !empty( $location ) ) :
$map_url = 'https://www.google.com/maps/dir/?api=1&destination=' . $location['lat'] . ',' . $location['lng'];
echo '<a href=". esc_url( $map_url ) . '" rel="nooopener">Get directions</a>';
endif;
?>
<p>This should produce a link like this:</p>
<a href="https://www.google.com/maps/dir/?api=1&destination=51.072159,1.088130">Get directions</a>
@mattradford
mattradford / acf_map_fallback.php
Last active September 1, 2015 14:18
ACF Google Map static image, for fallback
<img src="http://maps.google.com/maps/api/staticmap?center=<?php echo $location['lat']; ?>,<?php echo $location['lng']; ?>&markers=<?php echo $location['lat']; ?>,<?php echo $location['lng']; ?>&zoom=9&size=360x300&sensor=FALSE" />
<div class="acf-map--mobile" style="background-image:url('http://maps.google.com/maps/api/staticmap?center=<?php echo $location['lat']; ?>,<?php echo $location['lng']; ?>&markers=<?php echo $location['lat']; ?>,<?php echo $location['lng']; ?>&zoom=9&size=360x300&sensor=FALSE');"></div>
@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 / acf_post_parent_field.php
Created September 30, 2014 11:03
ACF get field from post parent
<?php $parent_id = $post->post_parent; ?>
<?php the_field('custom_field', $parent_id); ?>
@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 / acf_archive.php
Created October 7, 2014 11:50
Retrieve ACF custom fields on an archive page
// http://www.advancedcustomfields.com/resources/how-to-get-values-from-a-taxonomy-term/
<?php
// vars
$queried_object = get_queried_object();
$taxonomy = $queried_object->taxonomy;
$term_id = $queried_object->term_id;
?>
<?php the_field('show_usp_strip', $queried_object); ?>