Skip to content

Instantly share code, notes, and snippets.

View rickrduncan's full-sized avatar

Rick R. Duncan rickrduncan

View GitHub Profile
@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 / 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' ) ) {
<?php
//* Do NOT include the opening php tag shown above. Copy the code shown below.
//* Customize Genesis search form label
add_filter( 'genesis_search_form_label', 'b3m_search_form_label' );
function b3m_search_form_label ( $text ) {
return esc_attr( 'Enter your text here...' );
@rickrduncan
rickrduncan / functions.php
Last active January 17, 2016 18:05
Customize the Genesis Search Box with Icon Fonts: http://rickrduncan.com/wordpress/genesis-search-box-dashicons
<?php
//* Do NOT include the opening php tag
//* Enqueue FontAwesome. Note that the current version in the code is 4.5.0. Update as necessary.
//* https://codex.wordpress.org/Plugin_API/Action_Reference/wp_enqueue_scripts
//* https://fortawesome.github.io/Font-Awesome/icons/
<?php
//* Do NOT include the opening php tag
@rickrduncan
rickrduncan / 0_reuse_code.js
Created January 17, 2016 17:26
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
<?php
//* Do NOT include the opening php tag
//* Add theme info box into WordPress Dashboard
add_action('wp_dashboard_setup', 'b3m_add_dashboard_widgets' );
function b3m_add_dashboard_widgets() {
wp_add_dashboard_widget('wp_dashboard_widget', 'Theme Details', 'b3m_theme_info');
}
<?php
//* Do NOT include the opening php tag
//* Login Screen: Don't inform user which piece of credential was incorrect
add_filter ( 'login_errors', 'b3m_failed_login' );
function b3m_failed_login () {
return 'The login information you have entered is incorrect. Please try again.';
}
<?php
//* Do NOT include the opening php tag
//* Login Screen: Set 'remember me' to be checked
add_action( 'init', 'b3m_login_checked_remember_me' );
function b3m_login_checked_remember_me() {
add_filter( 'login_footer', 'b3m_rememberme_checked' )
;
}