Skip to content

Instantly share code, notes, and snippets.

@GrayofD4
GrayofD4 / wp-query-ref.php
Last active April 6, 2018 17:46 — forked from luetkemj/wp-query-ref.php
WP: Query $args
// This gist is now maintained on github at https://github.com/luetkemj/wp-query-ref
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.github.io
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
* Source: https://core.trac.wordpress.org/browser/tags/4.9.4/src/wp-includes/query.php
*/
@GrayofD4
GrayofD4 / shortcode-button.php
Created February 22, 2018 00:54
Simple button with various uses.
<?php
/*
Use cases:
[button href="/contact" text="contact us"]
[button href="/contact" text="contact us" /]
[button href="/contact"]Contact Us[/button]
[button]<a href="/contact/">Contact Us</a>[/button]
Available shortcode attributes
@GrayofD4
GrayofD4 / coming-soon.php
Created September 28, 2017 16:36
Dumb coming soon plugin, deactivate to remove, activate to add.
<?php
/*
Plugin Name: Coming Soon
Description: Dumb coming soon plugin, deactivate to remove, activate to add.
Version: 2017-07-13
Author: D4 Adv. Media
*/
function quickmaintenance_page() {
@GrayofD4
GrayofD4 / pre_get_posts-post-of-the-day.php
Created September 21, 2017 18:34
Redirect to post of the day
<?php
function show_post_of_the_day( $query ) {
if ( $query->is_home() && ! is_admin() && $query->is_main_query() ) {
$today = getdate();
$args = array(
'post_type' => 'post',
'date_query' => array(
@GrayofD4
GrayofD4 / chunk-pagination.php
Last active September 21, 2017 17:45
Looping Custom Post type pagination
<?php
echo $next_start;
$prev_post = get_adjacent_post( false, '', true );
#print_r($prev_post);
if ( is_a( $prev_post, 'WP_Post' ) ) {
previous_post_link( '%link', __('Previous' , 'skivvy') );
} else {
$first = new WP_Query('posts_per_page=1&order=DESC&post_type=saints');
$first->the_post();
@GrayofD4
GrayofD4 / shortcode-videochunk.php
Created August 24, 2017 23:50
Short code to randomly load youtube URLs and generate iframes.
<?php
// Code to add to page tempate to prevent oembed - remove_filter( 'the_content', array( $GLOBALS['wp_embed'], 'autoembed' ), 8 );
function shortcode_videochunk( $atts, $content = null ) {
$rand = explode(PHP_EOL, $content);
$rand = array_map('trim', $rand);
$rand = array_filter($rand, function($var){return ! empty($var);} );
shuffle( $rand );
<?php
function shortcode_example ( $atts ) {
$attr = shortcode_atts(array(
'defaults' => NULL
), $atts);
if ( isset($attr['defaults']) ) {
<?php
function client_info( $key = NULL ) {
$values = array(
'phone' => '1.555.5555',
'fax' => '1.555.5555',
'email' => '[email protected]',
'social' => array (
@GrayofD4
GrayofD4 / plugin-index.php
Last active April 7, 2017 22:08
Plugin Primer
<?php
/*
Plugin Name: D4 Functions
Description: Styles and functionality added by D4
Version: 2017-03-06
Author: D4 Adv. Media
*/
# include('config.php');
# include('lib/somefile.php');
@GrayofD4
GrayofD4 / slideshow-masthead.php
Last active August 31, 2016 18:42
Slideshow alternative that slides backgrounds behind the content of a shortcode
<?php
function shortcode_masthead( $atts, $content ) {
wp_enqueue_script('jcycle2');
$output .= '<div class="masthead-chunk">';
$output .= '<div ';
$output .= ' class="cycle-slideshow"'; // Initializing class, default for cycle2
# $output .= ' data-cycle-pager="#per-slide-template"'. // Connects to #per-slide-template box below
$output .= ' data-cycle-slides=".cycle-slide"'; // identifies the class identifier for slides