• Resolved webworklife

    (@webworklife)


    I am using the following code to redirect a Custom Post type to a PDF file in a ACF.
    How would I make the wp_redirect open the PDF in a new tab/window?

    function wwl_redirect_to_document() {
        if ( is_singular( 'documents' ) ) {
        $pdf_url = get_field( 'upload_file' );
        wp_redirect( $pdf_url );
        exit();
    	}
    }
    add_action( 'template_redirect', 'wwl_redirect_to_document' );
Viewing 1 replies (of 1 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    At least with template_redirect, I don’t think you’re going to be able to do that much with new windows and whatnot.

    Probably the better route is going to be amending the appropriate template files for archives and the like and checking if you have a pdf url, then dropping that url in place of the the_permalink() call. That way you have the ability to add the target="_blank" rel="noopener" attributes and open the new window that way.

    A bit messier than probably desired, but it gives you access to the anchor link that way.

Viewing 1 replies (of 1 total)

The topic ‘CPT + ACF Permalink’ is closed to new replies.