Title: Call to undefined function wp_generate_attachment_metadata()
Last modified: January 4, 2025

---

# Call to undefined function wp_generate_attachment_metadata()

 *  Resolved [mattce](https://wordpress.org/support/users/mattce/)
 * (@mattce)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/call-to-undefined-function-wp_generate_attachment_metadata-3/)
 * Hi,
 * I am using this plugin for a few years already, I’ve placed the “Phoenix_Media_Rename::
   do_rename” function inside a template to rename some images by passing by the
   attachment id. I don’t know exactly when it stopped working, because I didn’t
   touch this project for a while, but it was running fine in the past, seems to
   be caused by one of the plugin updates, but I cannot say which one unfortunately.
   
   Now it get this error when calling the template:`Fatal error: Uncaught Error:
   Call to undefined function wp_generate_attachment_metadata() in xxxx/wp-content/
   plugins/phoenix-media-rename/classes/class-media-rename.php:684 Stack trace: #
   0 xxxx/wp-content/themes/xxxx/template-rename-media.php(95): Phoenix_Media_Rename::
   do_rename() #1 xxxx/wp-includes/template-loader.php(106): include('…') #2 xxxx/
   wp-blog-header.php(19): require_once('…') #3 xxxx/index.php(17): require('…')#
   4 {main} thrown in xxxx/wp-content/plugins/phoenix-media-rename/classes/class-
   media-rename.php on line 684`
 * Any idea what has changed? [wp_generate_attachment_metadata()](https://developer.wordpress.org/reference/functions/wp_generate_attachment_metadata/)
   seems still to exist, not sure why it’s claiming that it’s undefined.
 * 
   Thanks a lot!
    -  This topic was modified 1 year, 3 months ago by [mattce](https://wordpress.org/support/users/mattce/).

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [crossi72](https://wordpress.org/support/users/crossi72/)
 * (@crossi72)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/call-to-undefined-function-wp_generate_attachment_metadata-3/#post-18233640)
 * Hi [@mattce](https://wordpress.org/support/users/mattce/),
   It is strange, because
   wp_generate_attachment_metadata is a WordPress’s core funcition, I’ll try to 
   replicate this issue on my development server.
 * If you are calling the do_rename methon on the frontend, there could be a problem
   because wp_generate_attachment_metadata could not be loaded, you can try this
   kind of solution:
 * `if ( ! function_exists( 'wp_generate_attachment_metadata' ) ) {
   require_once
   ABSPATH . 'wp-admin/includes/image.php';}
 * Let me know if you need more informations
   C
 *  Thread Starter [mattce](https://wordpress.org/support/users/mattce/)
 * (@mattce)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/call-to-undefined-function-wp_generate_attachment_metadata-3/#post-18238530)
 * You were totally right, by adding your provided snippet to my page template, 
   it started to work again.
   Thanks a lot! And thanks for your plugin in general,
   it’s really helpful.
 *  Plugin Author [crossi72](https://wordpress.org/support/users/crossi72/)
 * (@crossi72)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/call-to-undefined-function-wp_generate_attachment_metadata-3/#post-18241193)
 * It has been a pleasure 🙂
 * C.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Call to undefined function wp_generate_attachment_metadata()’ is closed
to new replies.

 * ![](https://ps.w.org/phoenix-media-rename/assets/icon-256x256.png?rev=3120623)
 * [Phoenix Media Rename](https://wordpress.org/plugins/phoenix-media-rename/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/phoenix-media-rename/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/phoenix-media-rename/)
 * [Active Topics](https://wordpress.org/support/plugin/phoenix-media-rename/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/phoenix-media-rename/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/phoenix-media-rename/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [crossi72](https://wordpress.org/support/users/crossi72/)
 * Last activity: [1 year, 3 months ago](https://wordpress.org/support/topic/call-to-undefined-function-wp_generate_attachment_metadata-3/#post-18241193)
 * Status: resolved