Skip to content

Instantly share code, notes, and snippets.

View aaronranard's full-sized avatar

Aaron Ranard aaronranard

View GitHub Profile
@aaronranard
aaronranard / Mobile_Detect.php
Created March 29, 2013 15:32
PHP: Mobile Detect
<?php
/**
* MIT License
* ===========
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
@aaronranard
aaronranard / feature.php
Last active December 15, 2015 18:39
WordPress: Get the Featured Image
<?php if (has_post_thumbnail( $project->ID )) : ?>
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $project->ID ), 'single-post-thumbnail' ); ?>
<img src="<?php echo $image[0]; ?>" alt="" />
<?php endif; ?>
@aaronranard
aaronranard / address-to-lat-long.php
Created July 23, 2013 15:13 — forked from bradp/gist:4999343
WordPress: Address to Latitude / Longitude
<?php
function brrad_geocode($street_address,$city,$state){
$street_address = str_replace(" ", "+", $street_address); //google doesn't like spaces in urls, but who does?
$city = str_replace(" ", "+", $city);
$state = str_replace(" ", "+", $state);
$url = "http://maps.googleapis.com/maps/api/geocode/json?address=$street_address,+$city,+$state&sensor=false";
$google_api_response = wp_remote_get( $url );
@aaronranard
aaronranard / edit-custom-category-list.php
Created July 23, 2013 20:04
WordPress: Edit Category / Post List
//Edit the Category List
add_filter( 'manage_edit-post_type_columns', 'set_custom_edit_post_type_columns' );
// Add to admin_init function
add_filter( 'manage_post_type_custom_column', 'manage_post_type_columns', 10, 3);
function manage_post_type_columns($out, $column_name, $id) {
switch ($column_name) {
case 'icon_image':
// Output custom post_type field here
@aaronranard
aaronranard / repeater.php
Last active December 22, 2015 18:39
WordPress: Repeater Field Loop
<?php if(have_rows('repeater_field_name')): ?>
<ul>
<?php while( have_rows('repeater_field_name')): the_row(); ?>
<li><?php echo get_sub_field('image'); ?></li>
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endwhile; ?>
</ul>
<?php endif; ?>
@aaronranard
aaronranard / search_functions.php
Created September 20, 2013 21:04
WordPress - Blank Search to go to search.php
//For blank searches to use search.php
add_filter( 'request', 'my_request_filter' );
function my_request_filter( $query_vars ) {
if( isset( $_GET['s'] ) && empty( $_GET['s'] ) ) {
$query_vars['s'] = " ";
}
return $query_vars;
}
@aaronranard
aaronranard / is_child.php
Created November 26, 2013 18:35
WordPress: is a child page
/**
* Child page conditional
* @ Accept's page ID, page slug or page title as parameters
*/
function is_child( $parent = '' ) {
global $post;
$parent_obj = get_page( $post->post_parent, ARRAY_A );
$parent = (string) $parent;
$parent_array = (array) $parent;
@aaronranard
aaronranard / custom-taxonomies.php
Last active August 29, 2015 13:58
WordPress - get custom taxonomies for post
$categories = get_the_terms( get_the_id() , 'service' );
$separator = '<br />';
$output = '';
if($categories){
foreach($categories as $category) {
//$output .= '<a href="'.get_category_link( $category->term_id ).'" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '">'.$category->cat_name.'</a>'.$separator;
$output .= $category->name . $separator;
}
echo trim($output, $separator);
}
@aaronranard
aaronranard / acf-gallery.php
Created April 8, 2014 17:00
WordPress: ACF - Output Gallery
@aaronranard
aaronranard / acf-gallery-lightbox.php
Created April 8, 2014 17:03
WordPress: ACF - Lightbox Gallery