Skip to content

Instantly share code, notes, and snippets.

View mattradford's full-sized avatar
👋

Matt Radford mattradford

👋
View GitHub Profile
@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 / acf_body_class.php
Last active September 18, 2020 20:30
Echo ACF custom field in body class
// ACF field added to body class
// Adapted from http://krogsgard.com/2012/wordpress-body-class-post-meta/
add_filter('body_class','tend_custom_field_body_class');
function tend_custom_field_body_class( $classes ) {
global $wp_query;
$postid = $wp_query->post->ID;
if ( is_page_template('template-service-index.php') ) {
@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,
@mattradford
mattradford / custom_excerpt_length.php
Created October 17, 2014 08:53
Custom excerpt length
function custom_excerpt_length( $length ) {
return 20;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
/* Limit Your Website Excerpt */
function word_limit($string, $max_words){
$post_words = explode(' ', $string);
$count = count($post_words);
$post_words = implode(' ', array_slice($post_words, 0, $max_words));
@mattradford
mattradford / wp_trim_words
Created October 17, 2014 08:56
Trim excerpt using built in function
wp_trim_words( $text, 55, ‘…’ );
@mattradford
mattradford / acf_carousel.php
Created October 23, 2014 10:39
ACF flexslider with carousel and image caption overlay
@mattradford
mattradford / acf_currency.php
Created October 23, 2014 11:06
ACF number field as formatted currency amount
<?php if(get_field('current_donations_total','options')) :
echo '&pound;' . number_format((get_field('current_donations_total','options')), 0, '.', ',');
endif; ?>
@mattradford
mattradford / flexlslider_fallback.css
Created October 23, 2014 14:36
Flexslider static image fallback if no Javascript
// Shows single image for all "flexslider-" sliders if JS is not enabled
.no-js {
[class^="flexslider"] {
li {
&:not(:first-child) {
display: none;
}
}
}
}
@mattradford
mattradford / email_page.js
Created October 31, 2014 13:56
Email current page with title
<script>
// Email current page with title
function emailCurrentPage(){
window.location.href="mailto:?subject="+document.title+"&body="+escape(window.location.href);
}
</script>
<a class="icon-mail" href="javascript:emailCurrentPage()"><span class="sr-only"><?php _e('Share via email','roots'); ?></a>