Skip to content

Instantly share code, notes, and snippets.

View jdhobbsuk's full-sized avatar

Jason Hobbs jdhobbsuk

View GitHub Profile
function render_acf_image( $img_obj, $fallback = '900x900', $prefix = '' ) {
if( !empty($img_obj) ):
$img_sizes = $img_obj['sizes'];
$breakpoints = array(
'xs' => '0px',
'sm' => '576px',
'md' => '768px',
'lg' => '992px',
@jdhobbsuk
jdhobbsuk / acf_get_file.php
Created January 19, 2016 15:05
Get the file URL from ACF, including file type and size
/**
* Get ACF File
*
* @param string $key – the ACF field key
* @param string $post_id – the ID of the post (if empty, will use $post->ID)
* @return string The image URL
**/
function get_acf_file( $key = 'file', $post_id = '' ) {
if($post_id == ''):
global $post;
@jdhobbsuk
jdhobbsuk / acf_get_image.php
Created January 19, 2016 15:04
Get the image URL from ACF, including choice of dimension (from add_image_size())
/**
* Get ACF Image
*
* @param string $size – the dimension of the image (using add_image_size() function)
* @param string $key – the ACF field key
* @param string $post_id – the ID of the post (if empty, will use $post->ID)
* @return string The image URL
**/
function get_acf_image( $size = 'full', $key = 'image', $post_id = '' ) {
@jdhobbsuk
jdhobbsuk / force-page-excerpt-into-admin.php
Created December 10, 2015 15:30
By default, users don't have excerpts displayed in the admin...this forces it.
// Force Page CPT to have excerpt (all users)
// -------------------------------------------------------------
if ( is_admin() ) :
function force_excerpt_box() {
// get all post types (excluding posts)
$post_types = array('page');
// get all users
$all_users = get_users( );
@jdhobbsuk
jdhobbsuk / time-formatting.php
Created September 1, 2015 09:52
Format time with removal of 00 (on hour), and auto compile start / end time
// Format date to remove 00 with on-hour times
// -------------------------------------------------------------
function mixd_format_time($time, $meridiem = false){
$full_time = intval($time);
$time = str_split($time, 2);
$hour = date('g', mktime($time[0], 0, 0, 1, 1, 2000));
$minute = $time[1];
$day_split = '';
@jdhobbsuk
jdhobbsuk / post-types.php
Created July 27, 2015 10:49
CPT using taxonomy in permalink
<?php
// Make CPT use taxonomy permalink
//--------------------------------------
add_filter('post_type_link', '<CPT>_permalink_filter_function', 1, 3);
function <CPT>_permalink_filter_function( $post_link, $id = 0, $leavename = FALSE ) {
if ( strpos('%<TAXONOMY>%', $post_link) === 'FALSE' ) {
return $post_link;
}
$post = get_post($id);
if ( !is_object($post) || $post->post_type != '<CPT>' ) {
@jdhobbsuk
jdhobbsuk / remove-columns-in-admin.php
Created June 3, 2015 15:47
Remove columns from admin list
// Remove columns from Page section
// -------------------------------------------------------------
function my_pages_columns( $defaults ) {
unset( $defaults['comments'] );
unset( $defaults['author'] );
unset( $defaults['tags'] );
unset( $defaults['date'] );
// WordPress SEO
unset( $defaults['wpseo-title'] );
@jdhobbsuk
jdhobbsuk / cpt-alphabetical-admin.php
Created June 3, 2015 14:31
Set custom post type to be listed alphabetically in the admin
// Set Meetup to alphabetical order and no pagination (in admin)
// -------------------------------------------------------------
function set_venue_admin_order($wp_query) {
if (is_admin()) {
$post_type = $wp_query->query['post_type'];
if ( $post_type == 'venue') {
$wp_query->set('orderby', 'title');
$wp_query->set('order', 'ASC');
@jdhobbsuk
jdhobbsuk / remove-pagination.php
Last active October 16, 2015 16:15
Remove pagination from post types (in admin)
// Force CPTs to have no pagination
// -------------------------------------------------------------
if ( is_admin() ) :
function force_no_admin_pagination() {
// get all post types (excluding posts)
$post_types = get_post_types();
unset($post_types['post']);
// get all users
@jdhobbsuk
jdhobbsuk / admin-cpt-filter.php
Last active August 29, 2015 14:22
Filter CPT by
// Add Hospital filter to CPTs (in admin)
// -------------------------------------------------------------
function restrict_people_by_hospital() {
global $typenow;
$taxonomy = 'hospital';
if ($typenow == 'consultant') {
$selected = isset($_GET[$taxonomy]) ? $_GET[$taxonomy] : '';
$info_taxonomy = get_taxonomy($taxonomy);
wp_dropdown_categories(array(
'show_option_all' => __("All {$info_taxonomy->label}s"),