Skip to content

Instantly share code, notes, and snippets.

Rick R. Duncan rickrduncan

View GitHub Profile
View GTM-LinkOpener.js
<script>
var links = document.links;
for (var i = 0, linksLength = links.length; i < linksLength; i++) {
if (links[i].hostname != window.location.hostname && links[i].protocol != 'tel:' && links[i].protocol != 'mailto:' ) {
links[i].target = '_blank';
links[i].rel = 'noopener noreferrer';
}
}
</script>
@rickrduncan
rickrduncan / author-breadcrumb.php
Last active Dec 21, 2018
Customize Genesis breadcrumb
View author-breadcrumb.php
<?php
//* Do NOT include the opening php tag
//* Prefix author breadcrumb trail with the text 'Articles written by'
add_filter( 'genesis_breadcrumb_args', 'b3m_prefix_author_breadcrumb' );
function b3m_prefix_author_breadcrumb( $args ) {
$args['labels']['author'] = 'Articles written by ';
return $args;
@rickrduncan
rickrduncan / genesis-page-titles-html5.php
Last active Nov 29, 2018
How to remove page titles from Genesis child themes using XHTML and HTML5 methods.
View genesis-page-titles-html5.php
<?php
//* Do NOT include the opening php tag
//* ALL EXAMPLES ON THIS PAGE USE THE NEW HTML5 METHOD
//* Remove page titles site wide (posts & pages) (requires HTML5 theme support)
remove_action( 'genesis_entry_header', 'genesis_do_post_title' );
@rickrduncan
rickrduncan / remove-cf7-css.php
Last active May 27, 2018
WordPress code snippet to remove contact form 7 bloat. Please visit http://rickrduncan.com/pro/wordpress/deregister-cf7-scripts-styles for details.
View remove-cf7-css.php
<?php
//* Do NOT include the opening php tag above
/**
*
* Remove Contact Form 7 CSS stylesheet from all pages except where needed.
*
*/
add_action('wp_print_styles', 'rrd_remove_cf7_css');
function rrd_remove_cf7_css() {
if ( function_exists( 'wpcf7_enqueue_styles' ) ) {
@rickrduncan
rickrduncan / wordpress-functionality-plugin.php
Last active Jan 21, 2018
This WordPress functionality plugin contains code snippets that tweak WordPress core and do not contain theme specific functionality. This is code that I run on every single website I build using WordPress.
View wordpress-functionality-plugin.php
<?php
/**
* Plugin Name: WordPress Functionality Plugin
* Plugin URI: http://rickrduncan.com/wordpress/functionality-plugin
* Description: Core WordPress customizations that are theme independent.
* Author: Rick R. Duncan - B3Marketing, LLC
* Author URI: http://rickrduncan.com
*
*
* Version: 1.0.0
@rickrduncan
rickrduncan / posts-orderby-modified-date.php
Last active Nov 14, 2017
Order Posts by modified date on Archive pages.
View posts-orderby-modified-date.php
<?php
//* Do NOT include the opening php tag above
/**
* Sort Posts by "last modified date"
*
*/
add_filter('posts_orderby', 'b3m_order_posts_by_mod_date', 999);
function b3m_order_posts_by_mod_date($orderby) {
if ( is_archive() ) {
@rickrduncan
rickrduncan / custom-genesis-search-form.php
Last active Nov 9, 2017
508 compliant Genesis search form
View custom-genesis-search-form.php
<?php
//* Do NOT include the opening php tag
//* Alter the Genesis Search for so that we can change the destination page and our querystring parameter.
add_filter( 'genesis_search_form', 'b3m_search_form', 10, 4);
function b3m_search_form( $form, $search_text, $button_text, $label ) {
$onfocus = " onfocus=\"if (this.value == '$search_text') {this.value = '';}\"";
$onblur = " onblur=\"if (this.value == '') {this.value = '$search_text';}\"";
$form = '<form role="search" method="get" class="searchform search-form" action="' . home_url() . '/search">
View custom_widgets.php
<?php
/**
* Recent_Posts widget class
*
* @since 2.8.0
*/
class WP_Widget_Recent_Posts_Custom extends WP_Widget_Recent_Posts {
function __construct() {
@rickrduncan
rickrduncan / schema-logo.php
Last active May 15, 2017
Filter the Genesis 2.0 SEO title to remove the H1 tag and implement the Organization/Logo schema.
View schema-logo.php
<?php
//* Do NOT include the opening php tag
//* Add Organization schema to our logo
//* Note that logo location is not inside WordPress. It's in a folder named 'img' off of the root of website.
add_filter( 'genesis_seo_title', 'b3m_header_title', 10, 3 );
function b3m_header_title( $title, $inside, $wrap ) {
$inside = sprintf( '<div itemscope="itemscope" itemtype="http://schema.org/Organization"><a itemprop="url" href="%s" title="%s"><img class="logo" itemprop="logo" src="http://www.YOUR-DOMAIN.com/img/YOUR-LOGO.png" alt="%s" /></a></div>', trailingslashit( home_url() ), esc_attr( get_bloginfo( 'name' ) ), get_bloginfo( 'name' ) );
return sprintf( '<%1$s id="title">%2$s</%1$s>', 'span', $inside );
}
@rickrduncan
rickrduncan / google-cse-genesis.php
Last active Nov 19, 2016
Google CSE for WordPress/Genesis Framework
View google-cse-genesis.php
<?php
/*
* Template Name: Google CSE
*
* This file adds the Google SERP template to our Genesis Child Theme.
*
* @author Rick R. Duncan
* @link http://rickrduncan.com
* @license http://www.opensource.org/licenses/gpl-license.php GPL v2.0 (or later)
*
You can’t perform that action at this time.