Skip to content

Instantly share code, notes, and snippets.

View WebEndevSnippets's full-sized avatar

Bruce Munson WebEndevSnippets

View GitHub Profile
@WebEndevSnippets
WebEndevSnippets / functions.php
Created January 4, 2014 15:03
WordPress: Add New Menu Navigation with dynamic child category walker class
//* Add New Menu Navigation with dynamic child category walker class
add_action( 'genesis_after_header', 'webendev_subcat_navigation', 15 );
function webendev_subcat_navigation() {
echo '<nav class="nav-primary">';
wp_nav_menu(
array(
'container_class' => 'wrap',
'theme_location' => 'primary',
'menu_class' => 'menu genesis-nav-menu menu-secondary',
'walker' => new Submenu_Walker_Nav_Menu()
@WebEndevSnippets
WebEndevSnippets / functions.php
Last active May 31, 2018 19:59
WordPress: New walker class to extend Walker_Nav_Menu. Dynamically adds child categories to menu.
add_action('wp_loaded','webendev_register_nav_menu_class');
/**
* New walker class to extend Walker_Nav_Menu
* Dynamically adds child categories to menu
*
*/
function webendev_register_nav_menu_class(){
class Submenu_Walker_Nav_Menu extends Walker_Nav_Menu {
@WebEndevSnippets
WebEndevSnippets / functions.php
Created January 3, 2014 20:03
Genesis : Add comment count and remove standard comment title
add_action( 'genesis_before_comments' , 'webendev_comment_count' );
/**
* Add comment count and remove standard comment title
*
*/
function webendev_comment_count () {
add_filter( 'genesis_title_comments', '_return_null' );
if ( is_single() ) {
if ( have_comments() ) {
echo '<h3>';
@WebEndevSnippets
WebEndevSnippets / functions.php
Created October 27, 2013 22:37
WordPress: Enqueue Font Awesome Stylesheet from MaxCDN
add_action( 'wp_enqueue_scripts', 'webendev_load_font_awesome', 99 );
/**
* Enqueue Font Awesome Stylesheet from MaxCDN
*
*/
function webendev_load_font_awesome() {
if ( ! is_admin() ) {
wp_enqueue_style( 'font-awesome', '//netdna.bootstrapcdn.com/font-awesome/4.0.1/css/font-awesome.css', null, '4.0.1' );
@WebEndevSnippets
WebEndevSnippets / functions.php
Created October 27, 2013 15:37
WordPress: Reduce Database Queries
Reduce database queries (http://www.catswhocode.com/blog/speeding-up-your-wordpress-blog-7-effective-solutions)
It is important to reduce unecessary queries to your database as each query take a few milliseconds to execute. First, you might want to know how many queries your blog execute in order to display a page. To do so, paste the code below in your functions.php file. Once done, just have a look to your site footer to know how many queries has been executed and how many time it took to completely load the page.
add_action( 'wp_footer', 'tcb_note_server_side_page_speed' );
function tcb_note_server_side_page_speed() {
date_default_timezone_set( get_option( 'timezone_string' ) );
$content = '[ ' . date( 'Y-m-d H:i:s T' ) . ' ] ';
$content .= 'Page created in ';
$content .= timer_stop( $display = 0, $precision = 2 );
$content .= ' seconds from ';
@WebEndevSnippets
WebEndevSnippets / functions.php
Last active December 22, 2015 23:09
Genesis: Add Image to Header Instead of background image (responsive).
add_filter( 'genesis_seo_title', 'webendev_add_logo_image_header', 10, 2 );
/**
* Filter the genesis_seo_site_title to use an image for the logo instead of a background image.
* This will allow full width logos to be reponsive. Requires CSS header width of 100%, and
* no min-height in header.
*
*/
function webendev_add_logo_image_header( $title, $inside ){
$child_inside = sprintf( '<a href="%s" title="%s"><img src="'. get_stylesheet_directory_uri() .'/images/StreetSyleDogs_Logo_980x226.jpg" title="%s" alt="%s"/></a>', trailingslashit( home_url() ), esc_attr( get_bloginfo( 'name' ) ), esc_attr( get_bloginfo( 'name' ) ), esc_attr( get_bloginfo( 'name' ) ) );
@WebEndevSnippets
WebEndevSnippets / functions.php
Created August 15, 2013 00:27
WordPress: Category Query - Sets all categories to xx per page
add_filter( 'pre_get_posts', 'we_archive_query' );
/**
* Category Query
*
* Sets all categories to 27 per page
* @since 1.0.0
* @link http://www.billerickson.net/customize-the-wordpress-query/
*
* @param object $query
*/
@WebEndevSnippets
WebEndevSnippets / functions.php
Created August 13, 2013 19:32
Plugin: Add rel="prettyPhoto" attribute automatically as image is inserted into post
add_filter( 'image_send_to_editor', 'we_insert_img_rel_attrib', 10, 6 );
/**
* Add rel="prettyPhoto" attribute automatically as image is inserted into post
* Requires PrettyPhoto JS enqueue
*/
function we_insert_img_rel_attrib( $html, $id, $caption, $title, $align, $url ) {
$rel = "<a rel=prettyPhoto";
if ($url) {$html = str_replace("<a",$rel,$html);}
return $html;
}
@WebEndevSnippets
WebEndevSnippets / functions.php
Last active December 20, 2015 23:09
WordPress: Load CSS with timestamp to bust cache
function rkv_cacheless_css() {
wp_enqueue_style( 'MY-CSS-NAME', MY-CSS-FILE.CSS, array(), time(), 'all' );
}
@WebEndevSnippets
WebEndevSnippets / functions.php
Created August 12, 2013 13:23
Genesis: Automatic cache busting in the Genesis Framework based on the last time the file was modified.(fatmedia)
// Remove the default Genesis child theme CSS
remove_action( 'genesis_meta', 'genesis_load_stylesheet' );
add_action( 'wp_enqueue_scripts', 'prefix_load_stylesheet' );
/**
* Get the time the theme's CSS was last modified
* and use it to bust the cache by appending
* it to the CSS output.
*
* @author FAT Media
* @link http://youneedfat.com