Skip to content

Instantly share code, notes, and snippets.

View davemac's full-sized avatar

davemac davemac

View GitHub Profile
@davemac
davemac / wp-orbit-cpt.php
Created November 13, 2012 00:17
Orbit Slider as WordPress custom post type
add_image_size( 'slider-image-large', 640, 280, true );
// Homepage Slider
add_action('init', 'register_dmc_orbit_slider');
function register_dmc_orbit_slider() {
$labels = array(
@davemac
davemac / gist:4145907
Created November 25, 2012 23:47
WordPress hide certain plugins
// thanks to Mike Little on WP-hackers
add_filter( 'all_plugins', 'dmc_remove_some_plugins' );
function dmc_remove_some_plugins( $all ) {
global $current_user;
$remove_these = array(
'limit-login-attempts/limit-login-attempts.php',
'wordpress-firewall-2/wordpress-firewall-2.php',
'update-notifier/update-notifier.php',
'wp-super-cache/wp-cache.php',
// http://wordpress.stackexchange.com/a/75512/131
if (has_post_thumbnail())
//if the post already has a post thumbnail then just use that
the_post_thumbnail($size = 'post-thumbnail', $attr = '');
else{
//if not then convert the custom field to the post thumbnail and display that
$at_url = get_post_meta($post->ID, 'image', true);
$at_id = get_image_id_by_url($at_url);
delete_post_meta($post->ID, 'image');
<?php # -*- coding: utf-8 -*-
/**
* Plugin Name: T5 Parent Terms in body_class
* Description: Adds all parent terms of a term archive to <code>body_class()</code>.
* Version: 2012.0.14
* Author: Thomas Scholz <[email protected]>
* Author URI: http://toscho.de
* License: MIT
* License URI: http://www.opensource.org/licenses/mit-license.php
*/
@davemac
davemac / gist:8577491
Created January 23, 2014 12:02
WordPress check if category is a parent
// check if category is a parent
function dmc_is_parentcat() {
$cat = get_query_var('cat');
$category = get_category($cat);
$category->parent;
return ( $category->parent == '0' ) ? true : false;
}
<?php
/*-----------------------------------------------------------------------------------*/
/* Conditional Logic to Detect Various Event Related Views/Pages
/*-----------------------------------------------------------------------------------*/
if( tribe_is_month() && !is_tax() ) { // Month View Page
echo 'were on the month view page';
} elseif( tribe_is_month() && is_tax() ) { // Month View Category Page
@davemac
davemac / For Deb, custom query to get child title, link and excerpt
Created March 5, 2014 03:31
For Deb, custom query to get child title, link, thumbnail image and excerpt
@davemac
davemac / gist:10362098
Created April 10, 2014 09:39
WordPress Get field from page parent
<?php
$parents = get_post_ancestors( $post->ID );
$id = ($parents) ? $parents[count($parents)-1]: $post->ID;
$title = ($parents) ? $parents[count($parents)-1]: $post->title;
?>
<?php if( get_field( 'dmc_hero_image', $id ) ) : ?>
<div class="row">
<div class="twelve columns page-title">
<img src="<?php the_field('dmc_hero_image', $id); ?>" width="990" class="hide-for-small" />
@davemac
davemac / gist:11312831
Created April 26, 2014 05:58
WordPress Require a Featured Post Image
add_action('save_post', 'wpds_check_thumbnail');
add_action('admin_notices', 'wpds_thumbnail_error');
function wpds_check_thumbnail($post_id) {
// change to any custom post type
if(get_post_type($post_id) != 'post')
return;
if ( !has_post_thumbnail( $post_id ) ) {
<?php
/**
* Change text strings
*
* @link http://codex.wordpress.org/Plugin_API/Filter_Reference/gettext
*/
function my_text_strings( $translated_text, $text, $domain ) {
switch ( $translated_text ) {
case 'Related Products' :
$translated_text = __( 'Check out these related products', 'woocommerce' );