Home › Forums › General Issues › Redirect to File URL › Reply To: Redirect to File URL
I was able to get this to work:
<?php
function redirect_to_acf_file_url() {
$file_url = get_field('file');
if (!empty($file_url) && is_string( $file_url ) ) {
wp_redirect( esc_url( $file_url ), 301);
exit;
}
}
redirect_to_acf_file_url();
?>
But curiously, now when I add a New Post and attach a file, the same way I’ve done in the past. The Redirect doesn’t work on the new post. When I change an select a new File to attach in an Existing Post, it similarly breaks also.
Please help!
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.