//remove sidebar from section templates in elementor editor
function remove_sidebar_elementor_section_templates( $layout ) {
if ( is_singular( 'elementor_library' ) ) {
$template_type = get_post_meta( get_the_ID(), '_elementor_template_type', true );
if ( 'section' === $template_type ) {
return 'no-sidebar';
}
}
return $layout;
}
add_filter( 'generate_sidebar_layout', 'remove_sidebar_elementor_section_templates' );
generatepress
categories and tags archive page
// create category and tags page - add a page called Categories for output
add_filter( 'template_include', 'to_category_page_template' );
function to_category_page_template( $template ) {
if ( ! is_page( array( 'categories', 'category' ) ) ) return $template;
add_filter( 'the_content', 'to_render_category_list' );
return $template;
}
function to_render_category_list( $content ) {
$categories = get_categories( array(
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => false,
'number' => 0, // get all, no limit
) );
if ( empty( $categories ) ) return $content;
// Index by term_id for easy lookup
$indexed = array();
foreach ( $categories as $cat ) {
$indexed[ $cat->term_id ] = $cat;
}
// Build tree
$tree = array();
foreach ( $categories as $cat ) {
$tree[ $cat->parent ][] = $cat;
}
$output = '<ul>' . to_render_category_branch( $tree, 0 ) . '</ul>';
// Tags
$tags = get_terms( array(
'taxonomy' => 'post_tag',
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => false,
'number' => 0,
) );
if ( ! empty( $tags ) && ! is_wp_error( $tags ) ) {
$output .= '<h2>Tags</h2><ul>';
foreach ( $tags as $tag ) {
$output .= '<li><a href="' . esc_url( get_tag_link( $tag->term_id ) ) . '">' . esc_html( $tag->name ) . '</a>';
if ( ! empty( $tag->description ) ) {
$output .= ' — ' . esc_html( $tag->description );
}
$output .= '</li>';
}
$output .= '</ul>';
}
return $content . $output;
}
function to_render_category_branch( $tree, $parent_id ) {
if ( empty( $tree[ $parent_id ] ) ) return '';
$output = '';
foreach ( $tree[ $parent_id ] as $category ) {
$output .= '<li>';
$output .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '">' . esc_html( $category->name ) . '</a>';
if ( ! empty( $category->description ) ) {
$output .= ' — ' . esc_html( $category->description );
}
if ( ! empty( $tree[ $category->term_id ] ) ) {
$output .= '<ul>' . to_render_category_branch( $tree, $category->term_id ) . '</ul>';
}
$output .= '</li>';
}
return $output;
}
create page ‘categories’ for it to display on.
gp control footer widths
.footer-widgets .footer-widget-1 {
flex-basis: 40%;
}
.footer-widgets .footer-widget-2 {
flex-basis: 20%;
}
.footer-widgets .footer-widget-3 {
flex-basis:30%;
}
.footer-widgets .footer-widget-4 {
flex-basis: 10%;
}
// GeneratePress Search Box Clear
add_filter( 'generate_navigation_search_output', 'tu_remove_search_query' );
function tu_remove_search_query() {
printf( // WPCS: XSS ok, sanitization ok.
'<form method="get" class="search-form navigation-search" action="%1$s">
<input type="search" class="search-field" value="" name="s" title="%2$s" />
</form>',
esc_url( home_url( '/' ) ),
esc_attr_x( 'Search', 'label', 'generatepress' )
);
}
generate press exclude categories from posts page
add_filter('pre_get_posts', 'excludeCat');
function excludeCat($query) {
if ( $query->is_home ) {
$query->set('cat', '-3,-5,-23');
}
return $query;
}
To hide Uncategorized posts use -1
disable block editor in widgets
// disable block editor */
add_filter( 'use_widgets_block_editor', '__return_false' );
gp hide featured image
/* generatepress hide featured image on all PAGES */
.single .page-header-image-single, .page-header-image, .page-header-image-single {
display: none;
}
/* show featured image on all POSTS */
article.category-music-leaders div.page-header-image-single {display: inherit;}
change generatepress color palette
previous solution
// change gp color palette
add_filter( 'generate_default_color_palettes', 'tu_custom_color_palettes' );
function tu_custom_color_palettes( $palettes ) {
$palettes = array(
'#351C4D', /* brand */
'#FEBF7B', /* accent */
'#FF7E5F', /* action */
'#765285', /* hover */
'#C1c1c1', /* light */
'#fe7b84', /* midtone */
'#000000', /* black */
'#FFFFFF', /* white */
);
return $palettes;
}
gp featured post excerpt length
// gp blog - featured post excerpt length
add_filter( 'excerpt_length', function( $length ) {
global $wp_query;
if ( 0 === $wp_query->current_post && !wp_is_mobile() ) {
// Set Length of first post on desktop
$length = 50;
} else {
// Set Length of other posts and all posts on mobile
$length = 20;
}
return $length;
}, 200);
empty cart in nav redirect to shop
// woo gp - navigation - empty cart redirect to shop
add_action( 'template_redirect', 'empty_cart_redirect' );
function empty_cart_redirect(){
if( is_cart() && WC()->cart->is_empty() ) {
wp_safe_redirect( get_permalink( wc_get_page_id( 'shop' ) ) );
exit();
}
}