Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Hot answers tagged

34

WordPress, by default, does a form of "Object Caching" but its lifetime is only a single page load. Options are actually a really good example of this. Check out this answer for more info. The summary: A page starts All options are loaded with a simple SELECT option_name, option_value from $wpdb->options statement Subsequent requests for those options (...


32

Add the filemtime() of your stylesheet as version parameter. Lets say, your default stylesheet is in css/default.css and css/default.min.css (not style.css). When we register a stylesheet on wp_loaded (not init), we can pass a version as fourth parameter. That will be the last modified time and therefore change every time we change the file. $min = ...


28

Object cache everywhere WordPress tries to reduce the number of database queries as much as possible. For example, anytime you get a meta field or a taxonomy field, before querying the database, WordPress looks if that that was already queried and stored in cache, and returns it from there instead of querying the database. The "cache job" is done via ...


23

The mix up is usually because these extensions are about two unrelated technologies: opcode caching and key-value data store. For WordPress you prefereably want both. Opcode caching is really the "normal" way to run PHP (and lack of it is essentially crippled shared hosting way). Data store can *(and should) be used by WordPress object cache plugins for ...


19

You don't have to use @import. It's best not to, actually. Using an enqueued approach is probably better all around. Here's the relevant part of twentythirteen's code: function twentythirteen_scripts_styles() { ... // Loads our main stylesheet. wp_enqueue_style( 'twentythirteen-style', get_stylesheet_uri(), array(), '2013-07-18' ); ... } add_action(...


18

Should I use Transient API at all here? No. In a stock WordPress install transients are stored in the wp_options table, and only cleaned up during core upgrades. Suppose you have 50,000 posts, that's 50,000 additional rows in the options table. Obviously they're set to autoload=no, so it's not going to consume all your memory, but there's another caveat. ...


14

Today I run a test over my db to explore the speed difference between accessing a key from options, custom table & transients. I ran the test for 1000 times and following is the time taken to run 1000 get operations: Keep in mind that the options table is used for both options and transients on most systems, and that table has been optimised, with ...


12

Not All WP Code Is Public Code If you are going to release something public, then all the things kovshenin said are perfectly valid. Things are different if you are going to write private code for yourself or your company. External Object Cache Is A Big Benefit, In Any Case To set a external persistent object cache is very recommended, when you can. All ...


11

Hm, I am not sure but I think that whole cache should be invalidated on publishing of new post... Had you tried to enable debug info in W3TC and check why are those pages aren't refreshed? As for manual cache clear, from plugin's FAQ: How can I flush the cache without using the WP Admin interface? It's possible to empty the entire cache or ...


11

Catching the weather API remote data The msg, you're showing in your question is basically the result from the weather API. And it says, that there's no data available for your location. The first thing you want to do is some research in the Codex and the "WP HTTP API". The right/WP way to grab remote data After you've learned about the WP HTTP API, you'...


11

At the moment, it is not possible. When 'pre_get_posts' runs, is too late to stop WP_Query to perform a query. WordPress itself, when you try to query a taxonomy that does not exists, adds AND (0 = 1) to the WHERE clause of the SQL query, to ensure it returns no results very quickly... There's a trac ticket with a patch that will probably lands in core ...


10

To flush a single page by post id in w3tc v0.9.3 I found this worked: if (function_exists('w3tc_pgcache_flush_post')){ w3tc_pgcache_flush_post($post_id); }


10

When and how to use transients or the object cache is a bit tricky and site-dependent. Here's the breakdown: When not using a persistent object cache (like memcached): Transients are stored in the database Objects in the object cache are only cached for the duration of the page request. When using a persistent object cache (like memcached): Transients ...


10

There is a hook for that: 'mce_css'. It is called in _WP_Editors::editor_settings() and you get all loaded stylesheets comma separated as the first and only parameter. Now it is easy: Use the global variable $editor_styles (here are your theme’s and parent theme’s editor stylesheets stored already), add the time of the file’s last modification as a ...


10

@dalbaeb's comment eventually lead to insightful discussions and a feasible solution. Thanks a lot! I believe the reason my child theme CSS was loaded using 'ver=<parent-theme-version> was because I had followed the WP Codex on child themes 1:1. My functions.php contained this: add_action('wp_enqueue_scripts', 'theme_enqueue_styles'); function ...


9

Bainternet's solution didn't seem to work for me. I'm successfully using this alternative snippet within a plugin, loaded at the admin_init action: // Clear all W3 Total Cache if( class_exists('W3_Plugin_TotalCacheAdmin') ) { $plugin_totalcacheadmin = & w3_instance('W3_Plugin_TotalCacheAdmin'); $plugin_totalcacheadmin->flush_all(); ...


9

I couldn't get toscho's answer to work for the current version of WordPress (4.7.2), and that seems to be because the TinyMCE init array has a cache_suffix set to 'wp-mce-' . $tinymce_version. So instead, you can just overwrite that with the tiny_mce_before_init filter, like so: function wpse33318_tiny_mce_before_init( $mce_init ) { $mce_init['...


9

I would not be storing 50+ meg as a transient. I would look into storing it in the filesystem somehow, or creating my own specific db table to store the data. Consider that if you're storing the transient in the database, then every time you pull it, that's 50 meg of data that has to be sent from the DB to the webserver for processing. And that's 50 meg of ...


9

This is directly related to, and a consequence of WordPress.com VIP At VIP, we deal with sites that range in the hundreds of millions of page views per week. As a result, situations that can slow down your site are much more noticeable at that scale than on a small shared host, but this still impacts a site with moderate traffic in the region of 100 or so ...


8

My previous answer is overly complicated and potentially doesn't respect the parent theme's dependency chain (see note in other answer). Here's another much simpler take that should work much better: function use_parent_theme_stylesheet() { // Use the parent theme's stylesheet return get_template_directory_uri() . '/style.css'; } function ...


8

It's because you're retrieving it via URL, but filemtime() requires a path. Use get_stylesheet_directory() instead. That returns a path: function pro_styles() { wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() .'/child-style.css', array(), filemtime(get_stylesheet_directory() .'/child-style.css'), 'all' ); } add_action( 'wp_enqueue_scripts', ...


7

Caching the WordPress Menu also gives you a performance boost. Especially if you have a lot of Pages or a giant Menu Structure, this should be considered. Do it in 2 easy steps. At first, create a function that gets or creates the menu, instead of calling wp_nav_menu directly. function get_cached_menu( $menuargs ) { if ( !isset( $menuargs['menu'] ) ) {...


7

After searching for a simple solution many times i decided to find something that works! so... after thinking about it i found a great way to override caching while developing new websites... (and its easy). What we need is to tell wp this is a new CSS version like this... Before changes: wp_enqueue_style( 'maincss', get_template_directory_uri() ...


7

Have you looked at WP_Object_Cache? If you suspect there is unwanted caching happening in the code that generates the admin panel then you might be able to use functions from the WP_Object_Cache to clear it. WP_Object_Cache is WordPress' class for caching data which may be computationally expensive to regenerate, such as the result of complex database ...


7

Is this ok or should I just store it in an array form so I can just directly access it without using json_decode? In your case store it directly means store it serialized. Because $data is an array and cannot be stored as is, but converted to a string. Even if you access it directly like: $data = get_transient('amazon_items'); print_r( $data[0] ); the ...


7

Yes, social counts are a great use case for using transients. Aside from the slow page loading, as you mentioned, this will also help prevent you from blowing through API limits if the external requests are being made on every page load. Let's say you have it set to cache for 30 minutes and the check for cache expiration is occurring when the data is ...


7

The wp_cache_*() functions are non-persistent caches which means that they only last during the current page request. This would be beneficial if you're requesting the same information multiple times during page load. For example, if you're showing recent posts in the header, content section, and sidebar ( calling the same code 3 times to retrieve recent ...


6

Static page cache is trade-off of resources for speed. The larger and more complex site is, the more resources it takes to cache it. Since there is no such thing as unwanted speed, static cache of small sized site is one of the best performance improvements possible. Especially on shared hosting where other tweaking options are very limited. CDN for ...


6

This might seem overly simple, but how about just disabling caching until you're done with the development portion of your site? It's more than simple to turn on and off.


6

The most common thing to try is a content caching plugin like W3 Total Cache or WP Super Cache. Both will cache entire pages to disk, and will allow the Apache web server to completely bypass PHP processing for many page views. With W3 Total Cache, you can also cache system objects and the results of database queries, as well as using a CDN (Content ...


Only top voted, non community-wiki answers of a minimum length are eligible