Various code snippets to customize Mai Theme
All of the following PHP snippets can safely be added on their own line at the bottom of functions.php file in Mai Theme.
Please note, many standard Genesis snippets/filters may need to run later when added to your Mai Theme (functions.php) file since most of our code runs early via the Mai Theme Engine plugin.
If your normal snippets don’t work as they typically do, before contacting support please try to wrap them in a later hook like the following:
Genesis functions to register/setup things
// Run after Mai Theme.
add_action( 'after_setup_theme', function() {
// Register custom widget area.
genesis_register_sidebar( array(
'id' => 'custom-widget-area',
'name' => __( 'Custom Widget Area', 'textdomain' ),
'description' => __( 'This is a custom widget area.', 'textdomain' ),
) );
});
For most front end things
// Run after Mai Theme.
add_action( 'genesis_before', function() {
// Add your custom code here.
});
Sticky Primary Navigation Menu
This snippet moves the primary navigation menu inside the header markup so it becomes sticky when Sticky Header setting is enabled in Mai Settings.
// Run after Mai Theme.
add_action( 'genesis_before', function() {
// Remove the primary navigation menu.
remove_action( 'genesis_after_header', 'genesis_do_nav' );
});
// Add primary nav after site-header closing wrap.
add_filter( 'genesis_structural_wrap-header', function( $output, $original_output ) {
if ( 'close' == $original_output ) {
// Build the new HTML.
ob_start();
genesis_do_nav();
$output .= ob_get_clean();
}
return $output;
}, 20, 2 );
Sticky Header Before Widget Area
// Run after Mai Theme.
add_action( 'genesis_before', function() {
// Remove header before widget area.
remove_action( 'genesis_header', 'mai_header_before', 2 );
});
// Add header before widget area before site-header opening wrap.
add_filter( 'genesis_structural_wrap-header', function( $output, $original_output ) {
// Bail if not the opening wrap.
if ( 'open' != $original_output ) {
return $output;
}
// Build the new HTML.
ob_start();
mai_header_before();
$header_before = ob_get_clean();
// Return it.
return $header_before . $output;
}, 4, 2 );
Search Form Text
// Run after Mai Theme.
add_action( 'genesis_before', function() {
// Customize search form input box text.
add_filter( 'genesis_search_text', function( $text ) {
return esc_attr( 'Search...' );
}
});
Featured Image Location
This snippet moves the featured image on single posts/pages after the title/meta (before the entry content).
// Move featured image before the content.
remove_action( 'genesis_before_entry', 'mai_do_entry_featured_image' );
add_action( 'genesis_before_entry_content', 'mai_do_entry_featured_image' );
Read More Text
// Replace the default "Read More" text in Mai Theme.
add_filter( 'mai_more_link_text', function( $text, $object_or_id, $type ) {
$text = 'Click Here';
return $text;
}, 10, 3 );
Post Info
// Run after Mai Theme.
add_action( 'genesis_before', function() {
// Customize post info.
add_filter( 'genesis_post_info', function( $post_info ) {
$post_info = ' ';
return $post_info;
});
});
Post Meta
// Run after Mai Theme.
add_action( 'genesis_before', function() {
// Customize post meta.
add_filter( 'genesis_post_meta', function( $post_meta ) {
$post_meta = ' ';
return $post_meta;
});
});
Post Meta Taxonomies
// Remove tags from post meta.
add_filter( 'mai_post_meta_taxos', function( $taxos ) {
unset( $taxos['post_tag'] );
return $taxos;
});
Remove Previous/Next Post Navigation
// Run after Mai Theme.
add_action( 'genesis_before', function() {
// Remove previous/next post navigation.
remove_post_type_support( 'post', 'genesis-adjacent-entry-nav' );
});
Add Content To [grid] Entries
/**
* Add content to the Mai Theme [grid] shortcode entry content, before more link.
*
* @param string $entry_content The existing entry content.
* @param array $args The sanitized grid args.
* @param array $original_args The original args passed the shortcode.
*
* @return string The modified entry content.
*/
add_filter( 'mai_flex_entry_content', function( $entry_content, $args, $original_args ) {
/**
* Check for a specific instance of grid.
* This requires context="my-custom-grid" as a parameter in your [grid] to target a specific instance.
* Or remove this conditional code to target all instances of grid.
*/
if ( 'my-custom-grid' !== $args['context'] ) {
return $entry_content;
}
// Add my custom content.
$new_content = '<p>My custom content here.</p>';
// Return our modified content.
return $new_content . $entry_content;
}, 10, 3 );
Change Image Size Used For Banner Area
Note: You can also filter the Image Sizes to change the actual dimensions of the default banner image size.
// Change the image size used for the banner area.
add_filter( 'mai_section_args', function( $args ) {
// Bail if not filtering the banner area.
if ( ! isset( $args['context'] ) || 'banner-area' !== $args['context'] ) {
return $args;
}
// Use the 'full' size image.
$args['image_size'] = 'full';
return $args;
});
Display Site Description/Tagline
// Run after Mai Theme.
add_action( 'genesis_before', function() {
// Make Mai Theme site description/tagline visible.
remove_filter( 'genesis_attr_site-description', 'mai_hide_site_description' );
});