Last active
August 7, 2025 03:21
-
-
Save n7studios/903bf57abacad46cec78c3829f82c69b to your computer and use it in GitHub Desktop.
WordPress to Buffer Pro: Set Link Preview URL from ACF Field
This file contains hidden or 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 | |
| /** | |
| * Plugin Name: WordPress to Buffer Pro: Set Link Preview URL from ACF Field | |
| * Plugin URI: http://www.wpzinc.com/ | |
| * Version: 0.0.1 | |
| * Author: WP Zinc | |
| * Author URI: http://www.wpzinc.com | |
| * Description: Define a non-WordPress Post URL from an ACF Field to be used as the Link Preview URL | |
| */ | |
| add_action( 'wp_to_buffer_pro_publish_build_args', function( $args, $post, $profile_id, $service, $status, $action ) { | |
| // Bail if ACF isn't installed. | |
| if ( ! function_exists( 'get_field' ) ) { | |
| return $args; | |
| } | |
| // Get ACF Field containing URL. | |
| $source_link = get_field( 'source_link', $post->ID ); | |
| // Ignore if no URL exists. | |
| if ( empty( $source_link ) ) { | |
| return $args; | |
| } | |
| // Set URL in media[link]. | |
| if ( ! array_key_exists( 'media', $args ) ) { | |
| $args['media'] = array(); | |
| } | |
| $args['media']['link'] = $source_link; | |
| return $args; | |
| }, 10, 6 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment