Skip to content

Instantly share code, notes, and snippets.

@jg314
jg314 / gist:4489182
Last active December 10, 2015 20:38
<?php
function add_styles_scripts(){
//Access the global $wp_version variable to see which version of WordPress is installed.
global $wp_version;
//If the WordPress version is greater than or equal to 3.5, then load the new WordPress color picker.
if ( 3.5 <= $wp_version ){
//Both the necessary css and javascript have been registered already by WordPress, so all we have to do is load them with their handle.
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script( 'wp-color-picker' );
<input id="color" name="color_options[color]" type="text" value="" />
<div id="colorpicker"></div>
@jg314
jg314 / gist:4489191
Last active December 10, 2015 20:38
//Set up the color pickers to work with our text input field
jQuery( document ).ready(function(){
"use strict";
//This if statement checks if the color picker widget exists within jQuery UI
//If it does exist then we initialize the WordPress color picker on our text input field
if( typeof jQuery.wp === 'object' && typeof jQuery.wp.wpColorPicker === 'function' ){
jQuery( '#color' ).wpColorPicker();
}
else {
@jg314
jg314 / nonprofit_board_management_plugin_frontend_members_shortcode.php
Last active December 28, 2015 04:29
Display all the board members for the Nonprofit Board Management plugin using a shortcode.
<?php
/*
* Display all the board members for the Nonprofit Board Management plugin
* using a shortcode.
*
* Copy and paste this code into your functions.php file to use it.
*
* example for use on a page: [list_board_members]
*/
function wi_list_board_members(){
@jg314
jg314 / gravity_forms_ga_tracking.php
Last active November 30, 2017 20:20
Add Google Analytics Ecommerce tracking to a donation form created through Gravity Forms.
<?php
/*
* Add custom query vars to handle Google Analytics Ecommerce tracking.
* This should be placed in a plugin or in functions.php of the theme.
*
* You'll want to use the redirect method for Gravity Forms confirmations and
* turn on passing field data via a query string. An example we used was:
* donation_amount={Donation Amount:13}&donation_id={entry_id}&donation_recurring=0
*/
function sm_add_query_vars( $vars ){
function tg_remove_home_breadcrumb($links)
{
if ($links[0]['url'] == get_home_url()) { array_shift($links); }
return $links;
}
add_filter('wpseo_breadcrumb_links', 'tg_remove_home_breadcrumb');
@jg314
jg314 / wp-picturefill.php
Last active August 29, 2015 14:06
WordPress Featured Image Using Picturefill Responsive Image Solution
<?php
//Created using code from http://scottjehl.github.io/picturefill/,
//http://ericportis.com/posts/2014/srcset-sizes/,
//http://www.taupecat.com/2014/05/picturefill-js-wordpress/,
//http://www.smashingmagazine.com/2014/05/12/picturefill-2-0-responsive-images-and-the-perfect-polyfill/
//For homepage where featured image should live
if( has_post_thumbnail() ){
$thumbnail_id = get_post_thumbnail_id();
$alt = get_post_meta( $thumbnail_id, '_wp_attachment_image_alt', true );
@jg314
jg314 / gravity_forms_pageview_track.html
Last active March 5, 2017 19:42
Google Analytics tracking code for virtual pageviews for Gravity Forms submissions that don't send users to a new page.
<!--
The js code snippet below should be placed in the confirmation text for a Gravity Form that does not send to a thank you
page on submission, such as a sidebar or footer email newsletter signup form.
* This snippet will work for forms that submit via both ajax and non-ajax.
* This snippet will work with plugins such as Google Analytics for WordPress by MonsterInsights.
* This snippet will work for Universal Analytics, but not Classic Analytics.
You can read more about tracking pageviews at https://developers.google.com/analytics/devguides/collection/analyticsjs/pages.
-->
@jg314
jg314 / ce-redirect.php
Last active December 11, 2020 18:31
Events Calendar Community Events: Redirect users to a new page after submission
<?php
/*
* Send visitors who submit events to a different page after submission.
*
* This actually does the redirect. If an event was submitted, and we're about
* to reload the submission page (with a message instead of a form), this will
* redirect the user.
*
* @param WP $wp
* @return void
@jg314
jg314 / wp_secondary_primary_nav.php
Created January 5, 2015 20:58
WordPress: Add secondary navigation to end of primary navigation in PHP for mobile.
<div class="main-navigation-container">
<nav id="site-navigation" class="main-navigation navigation" role="navigation">
<?php
$secondary_nav = wp_nav_menu( array(
'theme_location' => 'secondary',
'echo' => false,
'items_wrap' => '%3$s',
'container' => false
) );