Skip to content

Instantly share code, notes, and snippets.

View theukedge's full-sized avatar

Dave Clements theukedge

View GitHub Profile
@theukedge
theukedge / gist:3ab56ab58614e3baa0b4
Created January 28, 2015 18:17
Force HTTPS on all pages in WordPress
<?php function force_https () {
if ( !is_ssl() ) {
wp_redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 301 );
exit();
}
}
add_action ( 'template_redirect', 'force_https', 1 );
<?php // REGISTER TESTIMONIAL CPT
if ( ! function_exists('twpb_testimonial_cpt') ) {
function twpb_testimonial_cpt() {
$labels = array(
'name' => _x( 'Testimonials', 'Post Type General Name', 'twpb' ),
'singular_name' => _x( 'Testimonial', 'Post Type Singular Name', 'twpb' ),
'menu_name' => __( 'Testimonial', 'twpb' ),
<?php
global $post;
$tmp_post = $post;
$args = array( 'post_type' => 'events', 'numberposts' => $soupnumber, 'no_paging' => '1', 'post_status' => $posttype, 'order' => 'ASC', 'orderby' => $postorder, 'ignore_sticky_posts' => '1', 'category' => $soup_cat);
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<li><?php the_title(); ?></li>
<?php endforeach; ?>
<?php $post = $tmp_post; ?>
<?php function add_conversion_tracking_code($button, $form) {
$dom = new DOMDocument();
$dom->loadHTML($button);
$input = $dom->getElementsByTagName('input')->item(0);
if ($input->hasAttribute('onclick')) {
$input->setAttribute("onclick","ga('send', 'event', { eventCategory: 'Contact', eventAction: 'Mailing List Sign Up', eventLabel: 'Sidebar'});".$input->getAttribute("onclick"));
} else {
$input->setAttribute("onclick","ga('send', 'event', { eventCategory: 'Contact', eventAction: 'Mailing List Sign Up', eventLabel: 'Sidebar'});");
}
return $dom->saveHtml();
&copy;<?php echo date( 'Y' ); ?>
<?php // load parent theme CSS
function load_parent_theme_css() {
wp_enqueue_style( 'parent-theme', get_template_directory_uri() . '/style.css' );
}
add_action( 'wp_enqueue_scripts', 'load_parent_theme_css' );
<?php
// LOGOUT LINK IN MENU
function diww_menu_logout_link( $nav, $args ) {
$logoutlink = '<li><a href="'.wp_logout_url().'">Logout</a></li>';
if( $args->theme_location == 'main_menu' && is_user_logged_in() ) {
return $nav.$logoutlink ;
} else {
return $nav;
<?php
// Don't email webmaster for comment moderation
function pref_dont_email_webmaster( $emails, $comment_id ) {
$webmaster_email = get_option('admin_email');
if ( $emails[0] == $webmaster_email )
unset($emails[0]);
return (array) $emails;
}
<?php // IN THE SPOTLIGHT QUERY
if( false === ( $its_query = get_transient( 'its_query' ) ) ) {
$pttimestamp = time() + get_option('gmt_offset') * 60*60;
$its_query = new WP_Query( array(
'post_type' => 'spotlight',
'posts_per_page' => 1,
'meta_query' => array(
array(
'key' => '_hpc_spotlight_end_time',
'value' => $pttimestamp,