Skip to content

Instantly share code, notes, and snippets.

@cpaul007
Last active May 4, 2022 02:42
Show Gist options
  • Save cpaul007/b87ccd9e4c940e154f58ec8929f7f5a2 to your computer and use it in GitHub Desktop.
Save cpaul007/b87ccd9e4c940e154f58ec8929f7f5a2 to your computer and use it in GitHub Desktop.
Changing the initial offset value with ACF custom field
<?php //* do not include this line if you are adding into the functions.php file
/**
* Write the code in snippets plugin
*/
add_filter( 'before_after_image_initial_offset', 'ou_change_before_after_image_initial_offset');
function ou_change_before_after_image_initial_offset( $offset ) {
global $post;
if( ! is_a( $post, 'WP_Post') )
return $offset;
//* fetching the custom field data
$offset_value = get_post_meta( $post->ID, 'ENTER CUSTOM FIELD KEY', true );
if( ! empty( $offset_value ) )
return $offset_value;
return $offset;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment