[Resolved] Link Post format – open in new window

Home Forums Support [Resolved] Link Post format – open in new window

Home Forums Support Link Post format – open in new window

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1990447
    Marcus

    I’m trying to figure out how to have posts with the “link” post format open in a new window.

    I’m guessing I need a filter of sorts where I add target=”_blank” within the a tag.

    As it stands now, the archive page which lists the posts in this format correctly opens the link, instead of going to a detail / single post. The only thing I need now is just to have that link open in a new window.

    Thanks in advance guys!

    #1990455
    Ying
    Staff
    Customer Support

    Hi Marcus,

    Give this snippet a try:

    add_filter( 'generate_get_the_title_parameters', function( $params ) {
        if ( 'link' === get_post_format() ) {
    		$params = array(
    			'before' => sprintf(
    				'<h2 class="entry-title"%2$s><a target="_blank" href="%1$s" rel="bookmark">',
    				esc_url( generate_get_link_url() ),
    				'microdata' === generate_get_schema_type() ? ' itemprop="headline"' : ''
    			),
    			'after' => '</a></h2>',
    		);
    	}
        return $params;
    } );

    Let me know 🙂

    #1990457
    Marcus

    This is excellent Ying! Thank you.

    However, my apologies, because I did forget one detail. I need to also have the code test for the presence of a specific category:

    “/category/in-the-news/”

    Could he category test be added to the if statement?

    #1990471
    Ying
    Staff
    Customer Support

    Try this one 🙂

    add_filter( 'generate_get_the_title_parameters', function( $params ) {
        if ( 'link' === get_post_format() && is_category( 'in-the-news' ) ) {
    		$params = array(
    			'before' => sprintf(
    				'<h2 class="entry-title"%2$s><a target="_blank" href="%1$s" rel="bookmark">',
    				esc_url( generate_get_link_url() ),
    				'microdata' === generate_get_schema_type() ? ' itemprop="headline"' : ''
    			),
    			'after' => '</a></h2>',
    		);
    	}
        return $params;
    } );
    #1990485
    Marcus

    Perfect! You rock! #gpforever 🙂

    #1990518
    Ying
    Staff
    Customer Support

    You are welcome 🙂

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