Skip to content

Instantly share code, notes, and snippets.

@jg314
jg314 / comment_reply_emails.php
Created March 23, 2015 14:00
Send comment reply emails to the parent comment author automatically in WordPress.
<?php
add_action( 'wp_set_comment_status', 'wi_comment_notification', 99, 2 );
function wi_comment_notification( $comment_id, $comment_status ){
$comment_object = get_comment( $comment_id );
if( $comment_status == 'approve' && $comment_object->comment_parent > 0 ){
$comment_parent = get_comment( $comment_object->comment_parent );
$mailcontent = 'Hi ' . $comment_parent->comment_author . ',<br><br>';
$mailcontent .= $comment_object->comment_author . ' replied to your comment on <a href="' . get_permalink( $comment_parent->comment_post_ID ) . '">' . get_the_title( $comment_parent->comment_post_ID ).'</a> with the following:';
$mailcontent .= '<blockquote>' . $comment_object->comment_content . '</blockquote>';
@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
) );
@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 / 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 / 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 );
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 / 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 ){
@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 / 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 {
<input id="color" name="color_options[color]" type="text" value="" />
<div id="colorpicker"></div>