get_option() vs get_theme_mod(): Why is one slower?


I’ve been using get_theme_mod() for some time in various projects of mine. I decided to take advantage of the Theme Customization API in WordPress v3.4 once it was available as I felt it was an indispensable tool for my clients to use.

After some time, I began to notice that my sites were feeling a little more sluggish than usual, and the Customizer in particular took quite a long time to load. Through plenty of trial and error during my investigation, I decided to try switching out the type when registering my settings (i.e. $wp_customize->add_setting()) from theme_mod to option.

Once I did this and swapped out all of my get_theme_mod() calls to get_option(), I noticed a very significant increase in speed using the latter setup as opposed to the former on the frontend and especially in the Customizer on the backend. I’ve been looking through the WordPress core in an effort to try and figure out an answer for why this is, but can’t seem to discern what the particular hangup is in this scenario.

Any insights that the community might have with regards to get_option() performing significantly faster than get_theme_mod() would be greatly appreciated.

, , , , ntg2 3 years 2020-05-30T10:10:24-05:00 0 Answers 94 views 0

Leave an answer