Skip to content

Instantly share code, notes, and snippets.

Avatar

Aaron Ranard aaronranard

View GitHub Profile
View Mobile_Detect.php
<?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 Dec 15, 2015
WordPress: Get the Featured Image
View feature.php
<?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 Jul 23, 2013 — forked from bradp/gist:4999343
WordPress: Address to Latitude / Longitude
View address-to-lat-long.php
<?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 Jul 23, 2013
WordPress: Edit Category / Post List
View edit-custom-category-list.php
//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 Dec 22, 2015
WordPress: Repeater Field Loop
View repeater.php
<?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 Sep 20, 2013
WordPress - Blank Search to go to search.php
View search_functions.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 Nov 26, 2013
WordPress: is a child page
View is_child.php
/**
* 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 Aug 29, 2015
WordPress - get custom taxonomies for post
View custom-taxonomies.php
$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 Apr 8, 2014
WordPress: ACF - Output Gallery
View acf-gallery.php
@aaronranard
aaronranard / acf-gallery-lightbox.php
Created Apr 8, 2014
WordPress: ACF - Lightbox Gallery
View acf-gallery-lightbox.php
You can’t perform that action at this time.