generate_hook_element_display

generate_hook_element_display

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

For example, if we want to assign a specific hook to Author Tom only:

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

return $display;
}, 10, 2 );

Another useful example is to set the hook to display on the parent page and all the child pages automatically:

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 );

You need to replace 1180 with the ID of your Element, and 415 with the ID of the parent page.

generate_mobile_menu_media_query

generate_mobile_menu_media_query

Starting in GeneratePress 2.3, the generate_mobile_menu_media_query allows us to change when the mobile menu is initiated.

Default: 768px

To change the breakpoint to 1000px, we can use the follow PHP snippet:

add_filter( 'generate_mobile_menu_media_query', function() {
return '(max-width: 1000px)';
} );

If you change the media query with the above filter, you should also set the not mobile media query filter. This should be your breakpoint value + 1.

add_filter( 'generate_not_mobile_menu_media_query', function() {
return '(min-width: 1001px)';
} );

generate_post_author_output

generate_post_author_output

This filter returns the HTML that displays your post author along with your blog posts.

You can use this filter to completely overwrite the HTML given, or even add to it.

Add an Icon

For example, if you wanted to add an author icon before your author name, you could do this:

add_filter( 'generate_post_author_output', function( $output ) {
return ' ' . $output;
} );

Remove from Post Type

Another example is if you want to remove the author on a specific post type, but keep it elsewhere:

add_filter( 'generate_post_author_output', function( $output ) {
// If we're on our "my-post-type" post type, remove the author.
if ( is_post_type_archive( 'my-post-type' ) || 'my-post-type' == get_post_type() ) {
return '';
}

// Otherwise, display it.
return $output;
} );

Custom Author Name

One more example is if you want to completely customize your author name and link:

add_filter( 'generate_post_author_output', function( $output ) {
return 'My Name';
} );

Remove Link

Lastly, if you want to remove the link from the author:

add_filter( 'generate_post_author_output', function() {
printf( ' ',
sprintf( '%1$s %4$s',
__( 'by','generatepress'),
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ),
get_the_author() ) ),
esc_html( get_the_author() )
)
);
} );

Place Logo Next to Title

Place Logo Next to Title

Starting in GeneratePress 2.3, we』ve added an option to inline your logo and site branding (site title/tagline). This gives you a much better layout for those of you who wish to use both in their header.

Exclude Tags from Posts page

Exclude Tags from Posts page

Some users would like to exclude certain tags from the posts page. This can be done with the following PHP snippet:

function exclude_posts( $query ) {
if ( $query->is_home() ) {
$query->set( 'tag__not_in', array( 13 , 26 ) );
}
}
add_action( 'pre_get_posts', 'exclude_posts' );

Simply edit your tag IDs in there instead of the 13 and 26 (examples).

Sticky Navigation

Sticky Navigation

Note: This option requires the Menu Plus add-on in GP Premium.

Our Menu Plus add-on adds some really cool sticky navigation options inside Appearance > Customize > Layout > Sticky Navigation.

You can choose to activate your sticky navigation on mobile, desktop, both or disable it completely.

Sticky Navigation Transition

The Sticky Navigation Transition option has 3 choices:

Fade – your sticky navigation will fade in once you start scrolling.Slide – your sticky navigation will slide down once you start scrolling.None – there is no transition, as you start scrolling your navigation will simply stick to the top of your screen.

Hide when scrolling down

Checking this option will hide the sticky navigation unless you』re scrolling up towards the top of the site. This can save you valuable screen space, especially on mobile devices.

Sticky Navigation Logo

You can upload a logo specifically for sticky navigation.

Menu item height

You can also change the height of your navigation when it becomes sticky using this option.