Skip to content

Instantly share code, notes, and snippets.

@davechu
davechu / Genesis Auto Submenu
Last active February 1, 2016 15:28
This is code that will allow the use of Christian Varga's handy WordPress auto-submenu code.
/** dave's genesis code for making the submenu **/
add_action( 'wp_head', 'dc_add_tricky_menu' );
function dc_add_tricky_menu () {
// make all menus one level, or else dropdowns will be redundant in your submenu.
add_filter( 'wp_nav_menu_args', 'my_wp_nav_menu_args' );
// stick submenu under main menu. Of course you can use other hooks to put menu & submenu elsewhere.
add_action( 'genesis_after_header', 'dc_add_tricky_two' );
}
function my_wp_nav_menu_args( $args = '' ) {
.head-wrap {
position: fixed;
width: 100%;
z-index: 999;
min-height: 100px;
margin-bottom: 0;
}
.site-header, .header-image .site-title a {
min-height: 100px;
}
add_filter( 'genesis_post_meta', 'dc_post_meta_filter', 20 );
function dc_post_meta_filter($post_meta) {
$post_meta = do_shortcode('[post_categories before="Category: "] [post_tags before="Tags: "]');
return $post_meta;
}
// OR just pull out all Post Meta material. I'm sure you can think of cases for Post (or Custom Posts) that need none of this.
remove_action('genesis_entry_footer', 'genesis_post_meta');
// OR remove "Filed Under: " and separators, leaving just the category names and links. I have extra spaces for readability (optional).
// This will be in your child theme's functions.php.
// Change the figures below to match your header image size.
add_theme_support( 'genesis-custom-header', array(
'width' => 100,
'height' => 100
) );
@davechu
davechu / Search code for Yael
Last active August 29, 2015 13:58
This reduces search output so all you get is the phrase you searched on, followed by just links, no excerpt, meta, and so on.
<?php
/**
* Search Results Template File
*/
get_header(); ?>
<header>
<h1>Search Results: &quot;<?php echo get_search_query(); ?>&quot;</h1>
<br>
</header>
<?php if ( have_posts() ) : // results found?>
@davechu
davechu / Add Parent Page’s Body Class to Page Descendants in WordPress
Last active August 29, 2015 14:00
One code correction made for an error that appeared in debug mode. Thanks, Thad Bloom!
add_filter( 'body_class', 'dc_parent_body_class' );
function dc_parent_body_class( $classes ) {
if( is_page() ) {
$parents = get_post_ancestors( get_the_ID() );
$id = ($parents) ? $parents[count($parents)-1]: get_the_ID();
if ($id) {
$classes[] = 'top-parent-' . $id;
} else {
$classes[] = 'top-parent-' . get_the_ID();
}
@davechu
davechu / Remove Genesis Content From a Page
Last active August 29, 2015 14:02
This would go in functions.php. But you knew that! :)
add_action('genesis_before', 'dc_cut_out_content');
function dc_cut_out_content() {
if ( is_page('Sample Page') ) {
remove_action ('genesis_loop', 'genesis_do_loop');
remove_action( 'genesis_sidebar', 'genesis_do_sidebar' );
remove_action( 'genesis_sidebar_alt', 'genesis_do_sidebar_alt' );
}
}
@davechu
davechu / Change Comment Title
Last active August 29, 2015 14:02
For Elaine - this would go in your functions.php. The is_category could be made more specific if you wanted, of course. One slightly irritating global needed. :)
add_filter( 'comment_form_defaults', 'dc_change_form_title');
function dc_change_form_title($arg) {
$arg['title_reply'] = __('Please Comment');
return $arg;
}
@davechu
davechu / Unlink Sridhar's custom post type display
Last active August 29, 2015 14:02
These show the functions.php code before and after changes.
/** original code (don't copy this part) **/
if ( is_post_type_archive( 'staff' ) || is_singular( 'staff' ) || is_tax('staff-position') )
$post_meta = '[post_terms taxonomy="staff-position" before="Position: "]<br/>[post_tags before="Tagged With: "]';
/** this is the after (edited) code. be careful, watch the brackets! **/
if ( is_post_type_archive( 'staff' ) || is_singular( 'staff' ) || is_tax('staff-position') ) {
$post_meta = '[post_terms taxonomy="staff-position" before="Position: "]<br/>[post_tags before="Tagged With: "]';
add_filter( 'genesis_link_post_title', '__return_false' );
}