Design System is here - Read the release post

Learn GeneratePress

Developers

Elements and Page Hero filters

Filters for GP Premium’s Elements module (Hook, Block and Display elements) and Page Hero.

Jump to

Elements

generate_element_display

GP Premium — Elements module.

The generate_element_display allows us to bypass the Display Rules, so we can enable or disable an Element under our own conditions.

Parameters: $value. Default: the result of this element’s own Display Rules.

add_filter( 'generate_element_display', function( $display, $element_id ) {
    if ( 100 === $element_id && is_author( 'Tom' ) ) {
        $display = true;
    }

    return $display;
}, 10, 2 );
add_filter( 'generate_element_display', function( $display, $element_id ) {
    global $post; 

    if ( 100 === $element_id && is_single() && 'Tom' === get_the_author_meta( 'nickname', $post->post_author ) ) {
        $display = true;
    }

    return $display;
}, 10, 2 );
add_filter( 'generate_element_display', function( $display, $element_id ) {
    global $post;

    if ( 100 === $element_id && (( is_page() && $post->post_parent == '415' ) || is_page(415) )) {
        $display = true;
    }

    return $display;
}, 10, 2 );
add_filter( 'generate_element_display', function( $display, $element_id ) {
    global $post;
    $parent_category = get_term_by( 'slug', 'parent', 'category' );
    
    if ( $parent_category ) {
        $parent_category_id = $parent_category->term_id;
        $subcategories = get_term_children( $parent_category_id, 'category' );

        // Check if the post is in the subcategories
        if ( 100 === $element_id && ( is_single() &&  has_term( $subcategories, 'category', $post ) ) ) {
            $display = true;
        }
    }

    return $display;
}, 10, 2 );
add_filter( 'generate_element_display', function( $display, $element_id ) {
    if ( 100 === $element_id ) {
        if ( ! has_post_thumbnail() ) {
            $display = false;
        }
    }

    return $display;
}, 10, 2 );

Guide: Elements

generate_header_element_display

GP Premium — Elements module.

The generate_header_element_display allows us to bypass the Display Rules, so we can enable or disable an Element under our own conditions.

Parameters: $value. Default: GeneratePress_Conditions::show_data( $this->conditional, $this->exclude, $this->users ).

add_filter( 'generate_header_element_display', function( $display, $element_id ) {
    if ( 10 === $element_id && is_author( 'Tom' ) ) {
        $display = true;
    }

    return $display;
}, 10, 2 );
add_filter( 'generate_header_element_display', function( $display ) {
    if ( is_paged() ) {
       $display = false;
    }

    return $display;
} );
add_filter( 'generate_header_element_display', function( $display, $element_id ) {
    if ( 123 === $element_id ) { // Only target specific Element
        if ( ! has_post_thumbnail() ) {
            $display = false;
        }
    }

    return $display;
}, 10, 2 );
add_filter( 'generate_header_element_display', function( $display, $element_id ) {
    if ( 123 === $element_id ) { // Only target specific Element
        if ( !has_post_thumbnail($post->ID) || get_post_meta( get_the_ID(), '_generate-disable-post-image', true ) === 'true' ) {
            $display = false;
        }
    }
    return $display;
}, 10, 2 );

Guide: Elements

generate_hook_element_display

GP Premium — Elements module.

The generate_hook_element_display allows us to bypass the Display Rules, so we can enable or disable an Element under our own conditions.

Parameters: $value. Default: GeneratePress_Conditions::show_data( $this->conditional, $this->exclude, $this->users ).

add_filter( 'generate_hook_element_display', function( $display, $element_id ) {
    if ( 10 === $element_id && is_author( 'Tom' ) ) {
        $display = true;
    }

    return $display;
}, 10, 2 );
add_filter( 'generate_hook_element_display', function( $display, $element_id ) {
    global $post;

    if ( 1180 === $element_id && ( is_page() && $post->post_parent == '415' ) ) {
        $display = true;
    }

    return $display;
}, 10, 2 );

Guide: Elements

generate_layout_element_display

GP Premium — Elements module.

The generate_layout_element_display allows us to bypass the Display Rules, so we can enable or disable an Element under our own conditions.

Parameters: $value. Default: GeneratePress_Conditions::show_data( $this->conditional, $this->exclude, $this->users ).

add_filter( 'generate_layout_element_display', function( $display, $element_id ) {
    if ( 10 === $element_id && is_author( 'Tom' ) ) {
        $display = true;
    }

    return $display;
}, 10, 2 );

Guide: Elements

generate_elements_show_object_ids

GP Premium — Elements module.

The generate_elements_show_object_ids filter allows you to activate the ID next to the title in the Display Rules.

Parameters: $value. Default: false.

add_filter( 'generate_elements_show_object_ids', '__return_true' );

Guide: Elements

generate_hooks_capability

GP Premium — Hooks module.

The generate_hooks_capability filter allows you to specify user access to the Hooks add-on.

Parameters: $value. Default: 'manage_options'.

add_filter( 'generate_hooks_capability','tu_network_admin_hooks' );
function tu_network_admin_hooks() {
    return 'manage_network';
}

Guide: Elements

generate_hooks_execute_php

GP Premium — Elements module.

The generate_hooks_execute_php allows you to overwrite DISALLOW_FILE_EDIT and execute PHP within the Hooks Element.

Parameters: $value. Default: whatever PHP the Hook Element author entered.

add_filter( 'generate_hooks_execute_php', '__return_true' );

Guide: Elements

Back to top

Page Hero

generate_page_hero_location

GP Premium — Elements module.

The generate_page_hero_location allows you to move a page hero to other available hooks.

Parameters: $value. Default: 'generate_after_header'.

add_filter( 'generate_page_hero_location', function() {
	return 'generate_before_content';
} );

Guide: Page Hero

generate_page_hero_post_author

GP Premium — Elements module.

The generate_page_hero_post_author allows us to alter the HTML of the post author when using {{post_author}} template tag in header element.

Parameters: $value. Default: the post author’s display name.

add_filter( 'generate_page_hero_post_author', function() {
    global $post;
    $author_id = $post->post_author;

    return sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author"><span class="author-name" itemprop="name">%s</span></span>',
        esc_html( get_the_author_meta( 'display_name', $author_id ) )
    );
} );

Guide: Page Hero

generate_page_hero_terms_separator

GP Premium — Elements module.

The generate_page_hero_terms_separator filter allows us to alter or remove the comma between each category/tags inside Header Element.

Parameters: $value. Default: ', '.

add_filter( 'generate_page_hero_terms_separator', function() {
    return '';
} );

Guide: Page Hero

Back to top