Skip to content

Instantly share code, notes, and snippets.

Avatar

Devin Price devinsays

View GitHub Profile
View gist:4711952
<?php
/* Add a checkbox to the featured image metabox */
add_filter( 'admin_post_thumbnail_html', 'theme_featured_image_meta');
function theme_featured_image_meta( $content ) {
global $post;
// Text for checkbox
$text = __( "Don't display image on post.", 'textdomain' );
View gist:4711970
<?php
function prefix_enqueue_custom_script(){
wp_register_script( 'prefix_custom_script', plugin_dir_url( __FILE__ ) .'js/custom-script.js', array( 'jquery' ) );
wp_enqueue_script( 'prefix_custom_script' );
wp_localize_script( 'prefix_custom_script', 'optionsframework', array(
'hello' => __( 'Hello', 'textdomain' ),
'goodbye' => __( 'Good Bye', 'textdomain' )
) );
}
@devinsays
devinsays / postLoadImages
Created Mar 18, 2013
jQuery Plugin for post loading images
View postLoadImages
// jQuery Plugin for post loading images
$.fn.postLoadImages = function(callback) {
var imgLen = this.length,
count = 0;
return this.each(function(count) {
count++;
if ($(this).attr('data-src')) {
var imgTag = this, imgSrc = $(this).attr('data-src');
i = new Image();
@devinsays
devinsays / gist:5210667
Created Mar 21, 2013
Adds a "has-children" class to menu items that have children. Posted by @chipbennet to the Theme Reviewers Mail List.
View gist:5210667
function oenology_add_menu_parent_class( $items ) {
$parents = array();
foreach ( $items as $item ) {
if ( $item->menu_item_parent && $item->menu_item_parent > 0 ) {
$parents[] = $item->menu_item_parent;
}
}
foreach ( $items as $item ) {
@devinsays
devinsays / utm_tracking
Created Oct 4, 2013
Small jQuery plugin to add UTM tracking to links in an element.
View utm_tracking
jQuery.fn.utm_tracking = function(domain, source, medium, campaign) {
$(this).find('a[href^="' + domain + '"]').each(function() {
var url = $(this).attr('href');
$(this).attr( 'href', url + '?utm_source=' + source + '&utm_medium=' + medium + '&utm_campaign=' + campaign );
});
}
// Example Call
$(document).ready( function() {
$('body').utm_tracking('http://www.example.com','example_source','example_link','example_campaign');
@devinsays
devinsays / gist:884d6abe92857a329d99
Created May 27, 2014
Options Framework Top Level Options
View gist:884d6abe92857a329d99
function add_custom_options_page() {
$menu = $this->menu_settings();
switch( $menu['mode'] ) {
case 'menu':
// http://codex.wordpress.org/Function_Reference/add_menu_page
$this->options_screen = add_menu_page(
$menu['page_title'],
@devinsays
devinsays / custom_edd_sl_license_response
Last active Aug 29, 2015
Allow "Package" downloads. Multiple file downloads using the same license.
View custom_edd_sl_license_response
/**
* This code requires one additional filter param to be added to edd_sl_license_response in EDD_Software_Licensing.php:
* $response = apply_filters( 'edd_sl_license_response', $params, $download, $data)
*/
/**
* Allows EDD to bypass the name check for files
*/
define( 'EDD_BYPASS_NAME_CHECK', true );
@devinsays
devinsays / edd-csv-purchase-import.php
Created Jun 13, 2014
CSV Purchase Import for EDD
View edd-csv-purchase-import.php
<?php
/*
Plugin Name: Easy Digital Downloads - CSV Purchase Import
Plugin URL: http://easydigitaldownloads.com/extension/csv-purchase-import
Description: Allows you to import purchase history CSVs from other ecommerce systems
Version: 0.1
Author: Pippin Williamson
Author URI: http://pippinsplugins.com
Contributors: mordauk
*/
@devinsays
devinsays / customizer-controls-40
Last active Jul 16, 2018
WordPress 4.0 Customizer Controls
View customizer-controls-40
function prefix_customizer_register( $wp_customize ) {
$wp_customize->add_panel( 'panel_id', array(
'priority' => 10,
'capability' => 'edit_theme_options',
'theme_supports' => '',
'title' => __( 'Example Panel', 'textdomain' ),
'description' => __( 'Description of what this panel does.', 'textdomain' ),
) );
@devinsays
devinsays / gist:a4bc9bf08d27be51e29e
Last active Dec 7, 2018
custom-post-types-home-page
View gist:a4bc9bf08d27be51e29e
/**
* Load custom post type archive on home page
*
* Reference: http://www.wpaustralia.org/wordpress-forums/topic/pre_get_posts-and-is_front_page/
* Reference: http://wordpress.stackexchange.com/questions/30851/how-to-use-a-custom-post-type-archive-as-front-page
*/
function prefix_downloads_front_page( $query ) {
// Only filter the main query on the front-end
if ( is_admin() || ! $query->is_main_query() ) {