Created
February 8, 2019 01:45
-
-
Save jpcontrerasv/7c21b1f9c1fe62f19116ee7ef05923f1 to your computer and use it in GitHub Desktop.
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
add_filter('get_post_metadata', function($value, $object_id, $meta_key, $single) { | |
if ($meta_key !== '_thumbnail_id' || $value) { | |
return $value; | |
} | |
preg_match('~<img[^>]+wp-image-(\\d+)~', get_post_field('post_content', $object_id), $matches); | |
if ($matches) { | |
return $matches[1]; | |
} | |
return $value; | |
}, 10, 4); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment