Created
October 16, 2016 10:46
-
-
Save saxap/ed58287d5506a2a8e8cf1bab00ff80a0 to your computer and use it in GitHub Desktop.
Regenerate attachment on the fly wordpress
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
require_once( ABSPATH . 'wp-admin/includes/image.php' ); | |
$img_id = get_post_thumbnail_id( $service->ID ); | |
$parsed = parse_url( wp_get_attachment_url( $img_id ) ); | |
$url = ABSPATH . dirname( $parsed [ 'path' ] ) . '/' . rawurlencode( basename( $parsed[ 'path' ] ) ); | |
$url = str_replace('/', '/', $url); | |
$attach_data = wp_generate_attachment_metadata( $img_id, $url ); | |
wp_update_attachment_metadata( $img_id, $attach_data ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment