Skip to content

Instantly share code, notes, and snippets.

View justintadlock's full-sized avatar

Justin Tadlock justintadlock

View GitHub Profile
<?php
add_action( 'wp_enqueue_scripts', 'jt_enqueue_scripts' );
function jt_enqueue_scripts() {
wp_enqueue_script( 'wp-api' );
wp_enqueue_script( 'wp-util' );
}
add_action( 'wp_footer', 'jt_print_post_template', 25 );
<?php
/**
* The template for displaying home page.
*
* This is the template that displays all pages by default.
* Please note that this is the WordPress construct of pages
* and that other 'pages' on your WordPress site will use a
* different template.
*
* @package SKT Bakery
@justintadlock
justintadlock / control-select.php
Created June 7, 2015 06:46
Example customizer select control
<?php
class Hybrid_Customize_Control_Select extends WP_Customize_Control {
public $type = 'select-custom';
public function to_json() {
parent::to_json();
$this->json['choices'] = $this->choices;
@justintadlock
justintadlock / customize-empty-default-color.php
Last active August 29, 2015 14:21
Customize color with empty default
<?php
add_action( 'customize_register', 'my_customize_register' );
function my_customize_register( $wp_customize ) {
$wp_customize->add_setting(
'color_xyz',
array(
'default' => '',
@justintadlock
justintadlock / customize-control-dropdown-terms.php
Created May 8, 2015 17:04
Dropdown taxonomy terms customizer control
<?php
/**
* A dropdown taxonomy terms `<select>` customizer control class.
*
* @package Hybrid
* @subpackage Classes
* @author Justin Tadlock <[email protected]>
* @copyright Copyright (c) 2008 - 2015, Justin Tadlock
* @link http://themehybrid.com/hybrid-core
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
@justintadlock
justintadlock / customize-control-palette.php
Created May 4, 2015 01:06
Customize Control: Color Palette
<?php
/**
* Customize control class to handle color palettes.
*
* @package Hybrid
* @subpackage Classes
* @author Justin Tadlock <[email protected]>
* @copyright Copyright (c) 2008 - 2015, Justin Tadlock
* @link http://themehybrid.com/hybrid-core
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
@justintadlock
justintadlock / customize-control-radio-image.php
Last active September 5, 2018 17:14
Customize Control: Radio Image
<?php
/**
* The radio image customize control extends the WP_Customize_Control class. This class allows
* developers to create a list of image radio inputs.
*
* Note, the `$choices` array is slightly different than normal and should be in the form of
* `array(
* $value => array( 'url' => $image_url, 'label' => $text_label ),
* $value => array( 'url' => $image_url, 'label' => $text_label ),
* )`
@justintadlock
justintadlock / fruity-fruit.php
Last active February 20, 2023 13:07
Saving multiple meta values for a single key with a meta box.
<?php
/*
Plugin Name: Fruity Fruit
Description: An example plugin to test saving multiple meta values.
*/
add_action( 'add_meta_boxes_post', 'fruity_fruit_add_meta_boxes' );
add_action( 'save_post', 'fruity_fruit_save_meta', 10, 2 );
function fruity_fruit_add_meta_boxes() {
@justintadlock
justintadlock / customize-control-background-image.php
Created October 14, 2013 01:23
Class for registering multiple default backgrounds in WrodPress themes.
<?php
/**
* Extends the WordPress background image customize control class, which allows a theme to register
* multiple default backgrounds for the user to choose from. To use this, the theme author
* should remove the 'background_image' control and add this control in its place.
*
* @since 0.1.0
* @author Justin Tadlock <[email protected]>
* @copyright Copyright (c) 2013, Justin Tadlock
* @link http://justintadlock.com/archives/2013/10/13/registering-multiple-default-backgrounds
<!DOCTYPE html>
<html lang="en-EN">
<head>
<meta charset="UTF-8" />
<title>Test custom background &amp; header</title>
</head>
<body class="wordpress" itemscope="itemscope" itemtype="http://schema.org/WebPage">