Last active
August 29, 2015 14:13
-
-
Save magnificode/f0d7c7834ea5eee6ee2c to your computer and use it in GitHub Desktop.
Snippet that detects if a given ACF Page URL is an attachment page, detects the ID of that attachment page, and returns the URL for the actual attachment.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$ctaLink = get_field('static_hero_cta_button_link'); | |
if (false !== strpos($ctaLink,'attachment_id')) { | |
$url = $ctaLink; | |
$url_parsed = parse_url($url); | |
parse_str($url_parsed['query'], $url_parts); | |
$attachmentID = $url_parts['attachment_id']; // attachment ID | |
$attachmentSrc = wp_get_attachment_url( $attachmentID ); // returns an array | |
$ctaLink = $attachmentSrc; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment