Skip to content

Instantly share code, notes, and snippets.

@geeac
Last active October 6, 2022 18:33
Show Gist options
  • Save geeac/e0797d42c2ce3eee4c73e0924110d7ae to your computer and use it in GitHub Desktop.
Save geeac/e0797d42c2ce3eee4c73e0924110d7ae to your computer and use it in GitHub Desktop.
genesis basics
// completely disable image size threshold
add_filter( 'big_image_size_threshold', '__return_false' );
// increase the image size threshold to 3000px
function gc_big_image_size_threshold( $threshold ) {
return 3000; // new threshold
}
add_filter('big_image_size_threshold', 'gc_big_image_size_threshold', 999, 1);
define('WP_DISABLE_FATAL_ERROR_HANDLER',true);
// Make custom image sizes available to WP
add_filter( 'image_size_names_choose', 'gc_custom_image_sizes' );
function gc_custom_image_sizes( $sizes ) {
return array_merge( $sizes, array(
'square-entry-image' => __( 'Square Entry' ),
'vertical-entry-image' => __( 'Vertical Entry' ),
'horizontal-entry-image' => __( 'Horizontal Entry' ),
) );
}
// Remove Entry Header from homepage
add_action( 'genesis_before', 'gc_remove_entry_header' );
function gc_remove_entry_header() {
// if ( ! is_front_page() ) { return; }
// if ( is_home() || !is_page() ) { return; }
if ( ! class_exists( 'FLBuilderModel' ) || ! FLBuilderModel::is_builder_enabled() || ! is_page() ) { return; }
// Remove the entry header markup (requires HTML5 theme support)
remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_open', 5 );
remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_close', 15 );
// Remove the entry title (requires HTML5 theme support)
remove_action( 'genesis_entry_header', 'genesis_do_post_title' );
// Remove the entry meta in the entry header (requires HTML5 theme support)
remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );
// Remove the post format image (requires HTML5 theme support)
remove_action( 'genesis_entry_header', 'genesis_do_post_format_image', 4 );
}
// Remove Archive Title & Description from all the Genesis Archive Pages
//Removes Title and Description on CPT Archive
remove_action( 'genesis_before_loop', 'genesis_do_cpt_archive_title_description' );
//Removes Title and Description on Blog Archive
remove_action( 'genesis_before_loop', 'genesis_do_posts_page_heading' );
//Removes Title and Description on Date Archive
remove_action( 'genesis_before_loop', 'genesis_do_date_archive_title' );
//Removes Title and Description on Archive, Taxonomy, Category, Tag
remove_action( 'genesis_before_loop', 'genesis_do_taxonomy_title_description', 15 );
//Removes Title and Description on Author Archive
remove_action( 'genesis_before_loop', 'genesis_do_author_title_description', 15 );
//Removes Title and Description on Blog Template Page
remove_action( 'genesis_before_loop', 'genesis_do_blog_template_heading' );
// Move featured image above entry title in archives.
remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 );
add_action( 'genesis_entry_header', 'genesis_do_post_image', 8 );
// Remove entry content on blog and archives.
add_action ( 'genesis_before_entry' , 'gc_remove_entry_content_archives' );
function gc_remove_entry_content_archives() {
if (is_home() || is_archive() || is_search() )
remove_action( 'genesis_entry_content', 'genesis_do_post_content' );
}
// Remove Header Right widget area
unregister_sidebar( 'header-right' );
// Remove the secondary sidebar
unregister_sidebar( 'sidebar-alt' );
// Add support for after entry widget
add_theme_support( 'genesis-after-entry-widget-area' );
// Remove after entry widget
remove_action( 'genesis_after_entry', 'genesis_after_entry_widget_area' );
// Add after entry widget to posts and pages
add_action( 'genesis_after_entry', 'gc_after_entry', 9 );
function gc_after_entry() {
if ( ! is_singular( array( 'post', 'page' )) )
return;
genesis_widget_area( 'after-entry', array(
'before' => '<div class="after-entry widget-area">',
'after' => '</div>',
) );
}
// Change the footer credits
remove_action( 'genesis_footer', 'genesis_do_footer' );
add_action( 'genesis_footer', 'sp_custom_footer' );
function sp_custom_footer() {
echo '<p>Copyright '.do_shortcode('[footer_copyright]').' &middot; <a href="'.get_bloginfo( 'url' ).'">'. get_bloginfo( 'name' ) .'</a>. Design by <a href="https://greatoakcircle.com" target="_blank">Great Oak Circle</a>.</p>';
}
// Add Top Site widget area
add_action( 'genesis_header', 'gc_display_top_site', 10 );
function gc_display_top_site() {
genesis_widget_area('top-site',
array(
'before' => '<div class="top-site"><div class="wrap">',
'after' => '</div></div>',
)
);
}
genesis_register_sidebar( array(
'id' => 'top-site',
'name' => __( 'Top Site', 'genesis-sample' ),
'description' => __( 'This is the top site widget area.', 'genesis-sample' ),
) );
// Register the optin sidebar
genesis_register_sidebar( array(
'id' => 'optin',
'name' => __( 'Optin', 'genesis-sample' ),
'description' => __( 'This is the optin widget area.', 'genesis-sample' ),
) );
// Add support for custom logo.
add_theme_support( 'custom-logo', array(
'width' => 600,
'height' => 160,
'flex-width' => true,
'flex-height' => true,
) );
add_filter( 'genesis_seo_title', 'custom_header_inline_logo', 10, 3 );
/**
* Add an image inline in the site title element for the logo
*
* @param string $title Current markup of title.
* @param string $inside Markup inside the title.
* @param string $wrap Wrapping element for the title.
*
* @author @_AlphaBlossom
* @author @_neilgee
* @author @_JiveDig
* @author @_srikat
*/
function custom_header_inline_logo( $title, $inside, $wrap ) {
// If the custom logo function and custom logo exist, set the logo image element inside the wrapping tags.
if ( function_exists( 'has_custom_logo' ) && has_custom_logo() ) {
$inside = sprintf( '<span class="screen-reader-text">%s</span>%s', esc_html( get_bloginfo( 'name' ) ), get_custom_logo() );
} else {
// If no custom logo, wrap around the site name.
$inside = sprintf( '<a href="%s">%s</a>', trailingslashit( home_url() ), esc_html( get_bloginfo( 'name' ) ) );
}
// Build the title.
$title = genesis_markup( array(
'open' => sprintf( "<{$wrap} %s>", genesis_attr( 'site-title' ) ),
'close' => "</{$wrap}>",
'content' => $inside,
'context' => 'site-title',
'echo' => false,
'params' => array(
'wrap' => $wrap,
),
) );
return $title;
}
add_filter( 'genesis_attr_site-description', 'custom_add_site_description_class' );
/**
* Add class for screen readers to site description.
* This will keep the site description markup but will not have any visual presence on the page
* This runs if there is a logo image set in the Customizer.
*
* @param array $attributes Current attributes.
*
* @author @_neilgee
* @author @_srikat
*/
function custom_add_site_description_class( $attributes ) {
if ( function_exists( 'has_custom_logo' ) && has_custom_logo() ) {
$attributes['class'] .= ' screen-reader-text';
}
return $attributes;
}
// Add search form to navigation
add_filter( 'wp_nav_menu_items', 'gc_primary_nav_extras', 10, 2 );
function gc_primary_nav_extras( $menu, $args ) {
if ( 'primary' !== $args->theme_location ) {
return $menu;
}
ob_start();
get_search_form();
$search = ob_get_clean();
$menu .= '<li class="right search">' . $search . '</li>';
return $menu;
}
// Add widget to primary navigation
add_filter( 'genesis_nav_items', 'gc_social_icons', 10, 2 );
add_filter( 'wp_nav_menu_items', 'gc_social_icons', 10, 2 );
function gc_social_icons($menu, $args) {
$args = (array)$args;
if ( 'primary' !== $args['theme_location'] )
return $menu;
ob_start();
genesis_widget_area('nav-social-menu');
$social = ob_get_clean();
return $menu . $social;
}
genesis_register_sidebar( array(
'id' => 'nav-social-menu',
'name' => __( 'Nav Social Menu', 'text-domain' ),
'description' => __( 'This is the social media section that appears in the menu above the header.', 'text-domain' ),
) );
// Add search form to primary navigation on blog page
add_filter( 'wp_nav_menu_items', 'gc_primary_nav_search', 10, 2 );
function gc_primary_nav_search( $menu, $args ) {
if ( 'primary' !== $args->theme_location || !is_home() ) {
return $menu;
}
ob_start();
get_search_form();
$search = ob_get_clean();
$menu .= '<li class="right search">' . $search . '</li>';
return $menu;
}
// combine mobile menus
return [
'script' => [
'menuClasses' => [
'combine' => [
'.nav-primary',
'.nav-custom',
],
'others' => [ '.nav-primary' ],
],
],
'extras' => [
'media_query_width' => '960px',
],
];
// Replace Primary Nav conditionally
add_action( 'genesis_before', 'sk_replace_menu_in_primary' );
/**
* Conditionally replace Custom Menu in Primary Navigation.
*
* @author Sridhar Katakam
* @link http://sridharkatakam.com/conditionally-replace-navigation-menu-genesis/
*/
function sk_replace_menu_in_primary() {
if( is_page( 'about' ) ) { // Put your conditional here
add_filter( 'wp_nav_menu_args', 'replace_menu_in_primary' );
}
}
function replace_menu_in_primary( $args ) {
if ( $args['theme_location'] == 'primary' ) {
$args['menu'] = 'About Page Menu'; // Name of the custom menu that you would like to display in Primary Navigation location when the condition in earlier function is met
}
return $args;
}
// Add hamburger button to primary nav
add_filter( 'wp_nav_menu_items', 'gc_primary_nav_extras', 10, 2 );
function gc_primary_nav_extras( $menu, $args ) {
if ( 'primary' !== $args->theme_location ) {
return $menu;
}
$hamburger = '<button class="desktop-menu-toggle dashicons-before dashicons-menu" aria-expanded="false" aria-pressed="false" id="genesis-mobile-nav-secondary"></button>';
$menu .= $hamburger;
return $menu;
}
//fix incompatibility between The Events Calendar and Redis Cache
// Exclude The Events Calendar's post types from the object cache
add_filter( 'advanced_post_cache_skip_for_post_type', 'apc_exempted_cpts', 10,2);
function apc_exempted_cpts($return_me,$post_type) {
$exempted = array('tribe_events', 'tribe_venue', 'tribe_organizer', 'tribe_events_cat');
if ( in_array($post_type,$exempted) ) {
return true;
}
return $return_me;
}
// WC redirect base shop url
add_filter( 'woocommerce_return_to_shop_redirect', 'gc_woocommerce_shop_url' );
function gc_woocommerce_shop_url(){
return site_url() . '/custom-page/';
}
// WC Change continue shopping URL
add_filter( 'woocommerce_continue_shopping_redirect', 'gc_change_continue_shopping' );
function gc_change_continue_shopping() {
return wc_get_page_permalink( 'shop' ); // Change link
}
// Remove WP useless features
function mr_customise_wp() {
remove_action( 'admin_print_styles', 'print_emoji_styles' );
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
remove_action( 'wp_head', 'rsd_link' );
remove_action( 'wp_head', 'wlwmanifest_link' );
remove_action( 'wp_head', 'wp_shortlink_wp_head' );
add_filter( 'emoji_svg_url', '__return_false' );
add_filter( 'show_recent_comments_widget_style', '__return_false', 99 );
add_filter( 'tiny_mce_plugins', 'disable_emojicons_tinymce' );
add_filter( 'rest_enabled', '_return_false' );
add_filter( 'rest_jsonp_enabled', '_return_false' );
remove_action( 'wp_head', 'rest_output_link_wp_head' );
}
add_action( 'init', 'mr_customise_wp' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment