Site logo

[Resolved] Post format is not recognized in Query Loop

Home Forums Support [Resolved] Post format is not recognized in Query Loop

Home Forums Support Post format is not recognized in Query Loop

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #2411724
    Artem

    Hi,
    Hope you are well.

    I’d like my posts, with a “Link” post format, to open in a new tab. The solution provided by Ying works fine for archive pages:
    https://generatepress.com/forums/topic/link-post-format-open-in-new-window/

    However it doesn’t work for posts displayed via Query Loop. All posts open in the same tab. Apparently, post format is not recognized in Query Loop.
    Could you please recommend a solution on how to force Query loop to see post format.

    Many thanks.
    Artem

    #2412866
    David
    Staff
    Customer Support

    Hi there,

    where can i see this issue ?

    #2431039
    Artem

    Hi David,
    Sorry for the delay.
    The link is in the private info.
    Thanks a lot,
    Artem

    #2431117
    David
    Staff
    Customer Support

    Try this PHP Snippet:

    
    add_filter( 'render_block', function( $block_content, $block ) {
        
        if ( 
            !is_admin()
            && 'link' === get_post_format()
            && ! empty( $block['attrs']['className'] ) 
            && 'my-custom-class' === $block['attrs']['className'] 
        ) {
            $block_content = str_replace( '<a ', '<a target="_blank" ', $block_content );
        }
    
        return $block_content;
    }, 10, 2 );

    NOTE: this line: && 'my-custom-class' === $block['attrs']['className'] ) { change the my-custom-class to your own class. Then select the Headline block that has the link applied, and add that class to Advanced > Additional CSS Class(es)

    #2431985
    Artem

    Dear David,
    You make people happy.
    Thank you for you help.
    All the best

    #2432670
    David
    Staff
    Customer Support

    Glad we can be of help 🙂

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.