Skip to content

Instantly share code, notes, and snippets.

View rickrduncan's full-sized avatar

Rick R. Duncan rickrduncan

View GitHub Profile
@rickrduncan
rickrduncan / remove-seo.php
Created February 7, 2014 11:47
Remove 'SEO' from admin bar for users of WordPress SEO by Yoast. The code belongs in your functions.php file or better yet a functionality plugin.
<?php
//* Do NOT include the opening php tag
//* Remove the link 'SEO' from admin bar. It's placed there by the plugin WordPress SEO by Yoast.
add_action( 'wp_before_admin_bar_render', 'wlwp_admin_bar' );
function wlwp_admin_bar(){
global $wp_admin_bar;
$wp_admin_bar->remove_menu('wpseo-menu');
}
@rickrduncan
rickrduncan / genesis-page-titles-html5.php
Last active August 1, 2022 11:16
How to remove page titles from Genesis child themes using XHTML and HTML5 methods.
<?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 October 22, 2020 08:54
Customize Genesis breadcrumb
<?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 September 19, 2020 16:01
Add Google AdSense into WordPress category pages.
<!-- 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 October 3, 2019 04:34
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.
<?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 September 29, 2019 01:52
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.
<?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 / GTM-LinkOpener.js
Last active April 25, 2019 09:12
GTM code to open external links in a new tab. Learn more at http://rickrduncan.com/pro/analytics/open-external-links-new-tab-gtm.
<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 16:57
WordPress code snippet to remove contact form 7 bloat. Please visit http://rickrduncan.com/pro/wordpress/deregister-cf7-scripts-styles for details.
<?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 November 14, 2017 12:25
Order Posts by modified date on Archive pages.
<?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 November 9, 2017 07:29
508 compliant Genesis search form
<?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">