Skip to content

Instantly share code, notes, and snippets.

View davemac's full-sized avatar

davemac davemac

View GitHub Profile
<?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' );
@davemac
davemac / gist:a8c2b3eead05c859ecbe
Created August 14, 2014 00:32
Add custom RSS feed to Wordpress
function get_me_the_email_feed_template() {
add_filter('the_content_feed', 'css_tricks_super_awesome_feed_image_magic');
include(ABSPATH . '/wp-includes/feed-rss2.php' );
}
function css_tricks_super_awesome_feed_image_magic($content) {
// Weirdness we need to add to strip the doctype with later.
$content = '<div>' . $content . '</div>';
$doc = new DOMDocument('1.0', 'utf-8');
$doc->LoadHTML('<?xml encoding="UTF-8">' . $content);
@davemac
davemac / gist:21c27ef369864e458e18
Last active August 29, 2015 14:07
WordPress list custom post grouped by taxonomy term
<?php
$terms = get_terms( 'sponsor_type', array(
'orderby' => 'id',
) );
?>
<?php
foreach( $terms as $term ) {
@davemac
davemac / gist:fe8f93e2c302071ee290
Last active August 29, 2015 14:08
WP Sidebars
add_action( 'widgets_init', 'dmc_register_sidebars' );
function dmc_register_sidebars() {
register_sidebar(array(
'name'=> 'Conferences Sidebar',
'id' => 'sidebar-conferences',
'description' => 'Widgets placed here will appear in the sidebar on the Conferences pages',
'before_widget' => '<article id="%1$s" class="panel widget %2$s">',
'after_widget' => '</article>',
'before_title' => '<h4>',
@davemac
davemac / register_button
Created December 2, 2014 09:10
WordPress show button if event start date is before today's date
function register_button() {
$output = '';
$current_date = date_i18n('Y-m-d');
$date = DateTime::createFromFormat('jS F, Y', get_field('dmc_conference_date'));
$moddate = $date->format('Y-m-d');
if ( $moddate < $current_date ) :
$output .= '<a href="/pre-register-for-a-conference/" class="button radius large right">Pre-Register for 2015</a>';
else :
$output .= '<a href="' . esc_url(get_field('dmc_conference_rego_link')) . '" class="button radius large right">Register Now</a>';
endif;
@davemac
davemac / gist:23596001695f65625f07
Created December 12, 2014 08:54
WP remove menu options for user level
if ( ! current_user_can( 'manage_options' ) ) {
add_action( 'admin_menu', 'admin_menu_example' );
}
function admin_menu_example() {
remove_menu_page( 'index.php' ); //Dashboard
remove_menu_page( 'edit.php' ); //Posts
remove_menu_page( 'upload.php' ); //Media
remove_menu_page( 'edit.php?post_type=page' ); //Pages
remove_menu_page( 'edit-comments.php' ); //Comments