Home Forums General Issues Redirect to File URL Reply To: Redirect to File URL

  • Hi Andrew,

    Thanks for your help regardless of the confusion.
    We’re close! I’m using a Snippets plug-in to insert the PHP to the header of these specific Custom Post Types we don’t have to solve that.
    Therefore, I was really looking for that second part which Checks if the URL is not empty and Performs the redirect. The

    <?php>  function redirect_to_acf_file_url() {
            // Get the URL from the ACF file field, assuming the field name is 'file_url'
            $file_url = get_field('file_url', $post_id);
            // Check if the URL is not empty
            if (!empty($file_url)) {
                // Perform the redirect
                wp_redirect($file_url, 301);
    add_action('template_redirect', 'redirect_to_acf_file_url');

    I changed my own Field Name to file_url to match the code. Just to clarify, the Field on ACF is in fact a File field, these files are usually PDF.

    When the Resource post is accessed, we want them to bypass the post, straight into the URL of PDF file within the post, seclected through ACF.

    Let me know if there’s any more clarification needed.