Skip to content

Instantly share code, notes, and snippets.

View natebot's full-sized avatar

Nathan L. natebot

View GitHub Profile
@natebot
natebot / serial-commas-CAP.php
Last active May 26, 2017 02:04
Add support for serial commas to Co-Authors Plus WordPress plugin.
<?php
/**
* Add support for serial commas to Co-Authors Plus WordPress plugin.
* Filters coauthors_default_between_last to support serial commas (oxford comma) for 3 or more coauthors
*/
add_filter( 'coauthors_default_between_last', function( $between_last ) {
if ( ' and ' === $between_last && count( get_coauthors() ) > 2 ) {
$between_last = ', and ';
}
@natebot
natebot / content-tracking.js
Last active April 4, 2023 18:43
Basic attempt to
/**
* Tracking contnet reading with Google Analytics
*
* Requires jQuery and Underscores.
* Assumes Univerals Google Analytics object is available.
* 1) wrap your tracked content ( post body ) with div#content_tracking_start and div#content_tracking_end
* 2) Load this script in your footer after jQuery,Underscores, and GA.
*
* A) When the content is scrolled into the viewport we send off an event with the number of seconds between the start of the page and appearance of the content
* B) When the bottom of the content is scrolled into viewport we send off an event with nubmer of active seconds from the start of content and end of content.
@natebot
natebot / sailthru-widget-hack.php
Created October 31, 2014 23:24
SailThru plugin hack to prevent unnecessary loading of scrips and styles.
<?php
/**
* Force the unregistering of SailThru widgets and dequeue unused scripts and styles.
* If you don't have the SailThru widget on your site the plugin should not load the widget's styes and scripts.
* @todo the SailThru plugin should be improved to only enqueue when widgets are active
* I've submitted the fix patch: https://github.com/sailthru/sailthru-wordpress-plugin/pull/21
* Only use this hack if you never intend to use the SailThru widget, as it will break the Sailthru widget if you choose to activate it.
*/
add_action( 'widgets_init', function(){
unregister_widget( 'Sailthru_Subscribe_Widget' );
@natebot
natebot / sailthru_horizon_meta_tags_filter.php
Last active May 26, 2017 01:34
Filtering SailThru Horizon meta tags
<?php
/**
* Add support for CoAuthors Plus in SailThru plugin
* @see http://getstarted.sailthru.com/wordpress-vip-plugin
*/
add_filter( 'sailthru_horizon_meta_tags', function( $horizon_tags, $post_object ){
// If we are using the CoAuthors Plus plugin then we need to replace the value of sailthru.author
// If there are multiple authors we use a comma seperated list
if( is_single() && class_exists( 'coauthors_plus' ) && class_exists( 'Sailthru_Horizon' ) ){
$coauthors = (array) wp_list_pluck ( (array) get_coauthors(), 'display_name' ); // array of authors
@natebot
natebot / cap_feed.php
Last active December 22, 2015 04:28
WordPress Co-Authors-Plus: template helpers for getting co-authors for feeds. You must specify the dublic core namespace in your xml document.
<?php
function coauthors_feed() {
$authors = get_coauthors_feed(); // array of creator nodes, one for each author
echo wp_sprintf( '%l', $authors );
}
// uses dublin core specification for creator, so please specify dc namespace.
function get_coauthors_feed(){
$output = array();
@natebot
natebot / jetpack-open-graph-filter.php
Last active November 22, 2021 18:24
Filter jetpack open graph tags for fixes to og:meta and twitter cards, and adding support for Facebook's article:publisher tag for the WordPress VIP environment. Please note that you need to replace YOUR_TWITTER_HANDLE and YOUR_FACEBOOK_PAGE with appropriate values.
<?php
/* ------------------------------------------------------------------------------
* FILTER JETPACK OPEN GRAPH TAGS ADDITIONAL TWITTER CARD SUPPORT, FACEBOOK PUBLISHER, AND OG:META FIXES
* For the WordPress VIP environment.
* @see https://dev.twitter.com/docs/cards
* @see https://developers.facebook.com/blog/post/2013/06/19/platform-updates--new-open-graph-tags-for-media-publishers-and-more/
* ---------------------------------------------------------------------------- */
add_filter( 'jetpack_open_graph_tags', function( $tags ){
@natebot
natebot / is-meta-box-registered.php
Last active September 21, 2023 17:55
Test if a WordPress meta box has been registered.
<?php
/**
* Check if a meta box has been registered.
* Returns true if the supplied meta box id has been registered. false if not.
* Note that this does not check what page type
* @param String $meta_box_id An id for the meta box.
* @param String $post_type The post type the box is registered to (optional)
* @return mixed Returns boolean or a WP_Error if $wp_meta_boxes is not yet set.
*/