Skip to content

Instantly share code, notes, and snippets.

View justintadlock's full-sized avatar

Justin Tadlock justintadlock

View GitHub Profile
@justintadlock
justintadlock / in-main-loop.php
Last active February 11, 2024 20:23
A conditional tag for checking if we're in the core WP main query + loop.
<?php
/**
* Conditional to test if we're in the loop of the main query on a WordPress page.
* Please note that checking `in_the_loop() && is_main_query()` will NOT work in
* this scenario.
*/
add_action( 'loop_start', 'my_loop_start' );
add_action( 'loop_end', 'my_loop_end' );
@justintadlock
justintadlock / hybrid-media-grabber.php
Last active September 3, 2020 01:31
Media grabber class in development.
<?php
/**
* Hybrid Media Grabber - A script for grabbing media related to a post.
*
* Hybrid Media Grabber is a script for pulling media either from the post content or attached to the
* post. It's an attempt to consolidate the various methods that users have used over the years to
* embed media into their posts. This script was written so that theme developers could grab that
* media and use it in interesting ways within their themes. For example, a theme could get a video
* and display it on archive pages alongside the post excerpt.
*
<?php
/**
* Plugin Name: Theme Hybrid - API
* Plugin URI: http://themehybrid.com
* Description: API for ThemeHybrid.com
* Version: 0.1.0
* Author: Justin Tadlock
* Author URI: http://justintadlock.com
*/
@justintadlock
justintadlock / register-post-type.php
Last active October 22, 2023 05:55
Help file when registering post types.
<?php
# Register custom post types on the 'init' hook.
add_action( 'init', 'my_register_post_types' );
/**
* Registers post types needed by the plugin.
*
* @since 1.0.0
* @access public
@justintadlock
justintadlock / attr.php
Created October 7, 2013 00:38
Hybrid Core framework attributes proposal
<?php
/**
* HTML attribute functions and filters. The purposes of this is to provide a way for theme/plugin devs
* to hook into the attributes for specific HTML elements and create new or modify existing attributes.
* This is sort of like `body_class()`, `post_class()`, and `comment_class()` on steroids. Plus, it
* handles attributes for many more elements. The biggest benefit of using this is to provide richer
* microdata while being forward compatible with the ever-changing Web. Currently, the default microdata
* vocabulary supported is Schema.org.
*/
<!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">
@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 <justin@justintadlock.com>
* @copyright Copyright (c) 2013, Justin Tadlock
* @link http://justintadlock.com/archives/2013/10/13/registering-multiple-default-backgrounds
@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-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 / 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 <justin@justintadlock.com>
* @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