Title: Undefined variable: cachedir
Last modified: August 2, 2019

---

# Undefined variable: cachedir

 *  [fcadminn](https://wordpress.org/support/users/fcadminn/)
 * (@fcadminn)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/undefined-variable-cachedir/)
 * I am getting an error on amp pages:
 * Undefined variable: cachedir in /wp-content/plugins/amp-cache/ampforwp-cache.
   php on line 305.
 * Right now no amp pages are rendering. You can see this at [https://stadivm.com/cc/](https://stadivm.com/cc/).
 * Please advise on how to solve this. There seem to be many such errors that I 
   have encountered with AMPForWP and the cache plugin since using it. It is a great
   plugin, but these errors seem to be everywhere.
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fundefined-variable-cachedir%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

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

 *  Thread Starter [fcadminn](https://wordpress.org/support/users/fcadminn/)
 * (@fcadminn)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/undefined-variable-cachedir/#post-11793800)
 * PS. You have to go to the page on a mobile phone.
 *  Thread Starter [fcadminn](https://wordpress.org/support/users/fcadminn/)
 * (@fcadminn)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/undefined-variable-cachedir/#post-11793820)
 * Solved myself.
 * For future reference for anyone else encountering this specific issue, I went
   to line 305 in that file, found where the function containing it begins, and 
   added “global $cachedir;” just after the function statement on its own line.
 * If this is a correct solution for your team, please add to the next update.
 *  Thread Starter [fcadminn](https://wordpress.org/support/users/fcadminn/)
 * (@fcadminn)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/undefined-variable-cachedir/#post-11794150)
 * This did not solve the issue, but is only a temporary fix.
 * After a short amount of time, 403 forbidden errors are thrown on all posts.
 * Please provide a permanent fix for this issue.
 *  Plugin Author [Ahmed Kaludi](https://wordpress.org/support/users/ahmedkaludi/)
 * (@ahmedkaludi)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/undefined-variable-cachedir/#post-11797144)
 * Can you be specific on:
    1. what error you are getting exactly? 2. where are 
   you getting it?
 * So I can understand and help you
 *  Thread Starter [fcadminn](https://wordpress.org/support/users/fcadminn/)
 * (@fcadminn)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/undefined-variable-cachedir/#post-11797651)
 * I don’t know how I could be more specific. I answered both of your questions 
   in my initial message.
 * 1. what error you are getting exactly?
 * “Undefined variable: cachedir in /wp-content/plugins/amp-cache/ampforwp-cache.
   php on line 305.”
 * “Right now no amp pages are rendering.”
 * 2. where are you getting it?
 * “I am getting an error on amp pages”
 * “You can see this at [https://stadivm.com/cc&#8221](https://stadivm.com/cc&#8221);
 *  Thread Starter [fcadminn](https://wordpress.org/support/users/fcadminn/)
 * (@fcadminn)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/undefined-variable-cachedir/#post-11801947)
 * Hey just a follow up on this, it would be great to get this solved and have my
   amp pages working on mobile again. Currently no mobile users can view my posts
   and are getting an error message.
 * Thanks!
 *  Thread Starter [fcadminn](https://wordpress.org/support/users/fcadminn/)
 * (@fcadminn)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/undefined-variable-cachedir/#post-11819991)
 * In case anyone is looking for a solution to this.
 * Go to line 301 in /wp-content/plugins/amp-cache/ampforwp-cache.php, and edit 
   this if statement:
 * if($this->cachemod == ‘serverrewrite’){
    $cachedir=’ampforwp-cache/’; }
 * .. to just this:
 * $cachedir=’ampforwp-cache/’;
 * This is probably a hacky solution, but my AMP pages are now working on mobile
   again and no doubt there will be a patch for this error at a later date.

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

The topic ‘Undefined variable: cachedir’ is closed to new replies.

 * ![](https://ps.w.org/accelerated-mobile-pages/assets/icon-256x256.png?rev=1693616)
 * [AMP for WP - Accelerated Mobile Pages](https://wordpress.org/plugins/accelerated-mobile-pages/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/accelerated-mobile-pages/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/accelerated-mobile-pages/)
 * [Active Topics](https://wordpress.org/support/plugin/accelerated-mobile-pages/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/accelerated-mobile-pages/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/accelerated-mobile-pages/reviews/)

 * 7 replies
 * 2 participants
 * Last reply from: [fcadminn](https://wordpress.org/support/users/fcadminn/)
 * Last activity: [6 years, 9 months ago](https://wordpress.org/support/topic/undefined-variable-cachedir/#post-11819991)
 * Status: not a support question