Skip to content

Instantly share code, notes, and snippets.

Avatar

Rick R. Duncan rickrduncan

View GitHub Profile
@rickrduncan
rickrduncan / genesis-page-titles-html5.php
Last active Dec 9, 2020
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 / author-breadcrumb.php
Last active Oct 22, 2020
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 / google-adsense-archive-2.php
Last active Sep 19, 2020
Add Google AdSense into WordPress category pages.
View google-adsense-archive-2.php
<!-- STEP 2 -->
<!-- The code below is placed into a file named adsense-archive.php as noted in the Gist above. -->
<div id="archive-adsense-wrapper">
<div class="ad-left">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-xxxxxxxxxxxxx";
google_ad_slot = "xxxxxxxxx";
google_ad_width = 250;
google_ad_height = 250;
@rickrduncan
rickrduncan / oembed-gist.php
Last active Oct 3, 2019
A quick fix to this plugin: http://wordpress.org/plugins/oembed-gist/. Line 57, 61 & 69 were changed to rename the variable from 'gist' to 'oe-gist.' Line 79 was edited to add isset() to stop the error I was getting while testing.
View oembed-gist.php
<?php
/*
Plugin Name: oEmbed Gist
Plugin URI: http://firegoby.jp/wp/oembed-gist
Description: Embed source from gist.github.
Author: Takayuki Miyauchi
Version: 1.4.0
Author URI: http://firegoby.jp/
*/
@rickrduncan
rickrduncan / wordpress-functionality-plugin.php
Last active Sep 29, 2019
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
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 / 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 / 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() {