Skip to content

Instantly share code, notes, and snippets.

Avatar

Hal Gatewood halgatewood

View GitHub Profile
@halgatewood
halgatewood / wp-check-for-h1-custom-field.php
Created Jun 15, 2013
WP Check for H1 Custom Field value.
View wp-check-for-h1-custom-field.php
// H1 SUPPORT
function hg_check_for_h1_title($title, $id)
{
if (in_the_loop() AND $id == get_the_ID())
{
$h1 = get_post_meta($id, 'h1', true);
if($h1) return $h1;
}
return $title;
}
@halgatewood
halgatewood / YouTubeWidget.php
Last active Dec 18, 2015
Add a icon on top of the video by creating a youtube.png image and putting it in a 'images' folder in your theme.
View YouTubeWidget.php
<?php
/**
* Plugin Name: YouTube Video Widget
* Plugin URI: http://halgatewood.com/
* Description: Awesome YouTube Widget that allows single videos or latest video from channel. Uses transient api to keep it quick.
* Author: Hal Gatewood
* Author URI: http://halgatewood.com/
* Version: 1.0
* License: GPL v2 - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*
@halgatewood
halgatewood / pmpro-expire-at-end-of-year.php
Created Nov 20, 2013
Expire all membership levels at the end of the year. If the user registers after October (10 variable on line 8) then they'll expire in the next year.
View pmpro-expire-at-end-of-year.php
/// EXPIRATION DATE
function my_pmpro_checkout_level($level)
{
$expiration_year = date('Y');
$current_month = date('n');
// IF OCT, NOV, DEC, EXPIRE NEXT YEAR
if($current_month >= 10) { $expiration_year++; }
$expiration_date = $expiration_year . "-12-31";
@halgatewood
halgatewood / wordpress-3.8-dashicons.php
Last active Dec 29, 2015
WordPress 3.8: New Admin Menu Dashicons
View wordpress-3.8-dashicons.php
function flexslider_hg_admin_icon()
{
echo '
<style>
#adminmenu #menu-posts-slides div.wp-menu-image:before { content: "\f181"; }
</style>
';
}
add_action( 'admin_head', 'flexslider_hg_admin_icon' );
@halgatewood
halgatewood / acf-youtube-video-object.php
Created Dec 26, 2013
Working with the Video Object in the Advanced Custom Fields: YouTube Field. http://halgatewood.com/downloads/acf-youtube-field/
View acf-youtube-video-object.php
$video = get_field('youtube_video');
echo "<h1>" . $video->title . "</h1>";
echo "<p>" . $video->desc . "</p>";
echo $video->embed;
@halgatewood
halgatewood / page-https.php
Created Feb 13, 2014
HTTPS Page in Wordpress
View page-https.php
<?php
/**
* Template Name: HTTPS Page
*/
if($_SERVER['HTTPS']!="on")
{
wp_redirect( "https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
exit;
}
View change-testimonial-archive-order.php
function hg_change_archive_order( $query )
{
if($query->is_archive AND $query->query['post_type'] == "testimonial")
{
$query->set( 'order' , 'asc' );
$query->set( 'orderby' , 'title' );
}
}
add_filter( 'pre_get_posts' , 'hg_change_archive_order' );
View changing-widget-testimonial-order.php
function testimonial_rotator_change_order( $args )
{
$args['order'] = "DESC";
$args['orderby'] = "date";
return $args;
}
// USE THIS add_filter FOR THE WIDGET
add_filter('testimonial_rotator_widget_testimonial_args', 'testimonial_rotator_change_order');
View wp-color-palettes
global $_wp_admin_css_colors;
$color_scheme = get_user_option( 'admin_color' );
$current_admin_color_theme = $_wp_admin_css_colors[ $color_scheme ];
echo '
<style>
img.icon { color: ' . $current_admin_color_theme->colors[2] . '; }
img.icon.selected { color: ' . $current_admin_color_theme->colors[3] . '; }
</style>';
View wp-color-object
stdClass Object
(
[name] => Default
[url] => https://halgatewood.com/wp-admin/css/colors.min.css
[colors] => Array
(
[0] => #222, [1] => #333, [2] => #0074a2, [3] => #2ea2cc
)
[icon_colors] => Array
(