Skip to content

Instantly share code, notes, and snippets.

View devinsays's full-sized avatar

Devin Price devinsays

View GitHub Profile
<?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' );
<?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 March 18, 2013 04:50
jQuery Plugin for post loading images
// 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 March 21, 2013 04:22
Adds a "has-children" class to menu items that have children. Posted by @chipbennet to the Theme Reviewers Mail List.
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 October 4, 2013 19:18
Small jQuery plugin to add UTM tracking to links in an element.
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 21:02
Options Framework Top Level Options
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 August 29, 2015 14:02
Allow "Package" downloads. Multiple file downloads using the same license.
/**
* 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 June 13, 2014 19:31
CSV Purchase Import for EDD
<?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 April 20, 2023 10:03
WordPress 4.0 Customizer Controls
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 December 7, 2018 19:53
custom-post-types-home-page
/**
* 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() ) {