So, I have a walker nav menu who add the page excerpt to all page links in the nav menu.
Now, I want to build a custom post excerpt for the blog archive.
All works fine when the nav menu doesn't meet the Blog Archive. On the blog archive the nav menu's excerpts get the filter of the blog archive. This is because the excerpt filter checks on the current post.
Is there a way for the excerpt filter to check on the queried item in stead of the current post? As with the walker menu...
Here are the filters I use:
For the walker menu
function q_menu_item_custom_output( $item_output, $item, $depth, $args ) {
$excerpt_el = '';
$p_id = $item->object_id;
if ( has_excerpt( $p_id ) ) {
$excerpt_el = '<span class="excerpt">' . get_the_excerpt($p_id) . '</span>';
}
return $item_output . $excerpt_el;
}
add_filter( 'walker_nav_menu_start_el', 'q_menu_item_custom_output', 10, 4 );
and for the post excerpt:
function q_excerpt_custom( $excerpt ) {
if ( get_post_type( ) == 'post' ) :
$excerpt_custom = '<a class="card-permalink" href="' . get_permalink() . '" rel="nofollow"> HA HA HA </a>';
return $excerpt_custom;
endif;
return $excerpt;
}
add_filter( 'get_the_excerpt', 'q_excerpt_custom' );
Thank you!