Free themes are designed to be as easy to install as possible. You simply upload your theme, activate it, and you’re done. It knows your blog’s name, description, feed URL and everything else.
In order to know all of this, the theme uses PHP tags to get the information. However, it has to use these tags every time a page is loaded.
As most of the information never changes, you can delete these tags from your theme, and replace them with normal text. That way, your server has less to process next time around.
13 Common Tags in WordPress Themes
The easiest way to replace the tags is to load up a page from your blog, then “View Source.” Now go through your theme and look for the following tags, then find what each tag corresponds to in your page source. Paste the text from the page source over the theme tags.
Save the files after every change and check that the new version of the page is identical to the old.
- <?php language_attributes(); ?> found in header.php.
- <?php bloginfo(‘html_type’); ?> found in header.php.
- <?php bloginfo(‘charset’); ?> found in header.php.
- <?php bloginfo(‘name’); ?> found throughout the theme.
- <meta name=”generator” content=”WordPress <?php bloginfo(‘version’); ?>” /> <!– leave this for stats –> found in header.php. If you’re using a 3rd party stats program (like Google Analytics) then you’ve nothing to worry about, and if your version of WordPress is out of date, you won’t want hackers knowing that.
- <?php bloginfo(’stylesheet_url’); ?> found in header.php.
- <?php bloginfo(‘rss2_url’); ?> founder in header.php, sidebar.php and footer.php. Be careful if you switch to FeedBurner after doing this. Make sure you remember to update the feed URL here manually (The FeedSmith plugin won’t do it anymore).
- <?php bloginfo(‘pingback_url’); ?> found in header.php.
- <?php bloginfo(’stylesheet_directory’); ?> found throughout the theme.
- <?php bloginfo(‘description’); ?> found throughout the theme. Your site’s slogan.
- <?php bloginfo(‘comments_rss2_url’); ?> found in sidebar.php and footer.php.
- <!– <?php echo get_num_queries(); ?> queries. <?php timer_stop(1); ?> seconds. –> found in footer.php. This HTML comment won’t be overly useful to many of us, so delete away!
- If you are using widgets, you can also delete the code in sidebar.php between the lines<?php /* Widgetized sidebar, if you have the plugin installed. */
if ( !function_exists(‘dynamic_sidebar’) || !dynamic_sidebar() ) : ?>
and
<?php endif; ?>
Content between these 2 lines is only used if widgets are not enabled. If you know that you will continue to use widgets, then there is no need for any code here (It may be worth leaving a comment along the lines of “Content here used if widgets are disabled” to remind yourself of this in the future).
By removing these, you’ll shave the load of your server and pages will be constructed that bit faster.
Custom Search
AL (11 comments)8 October 07
Cool tips. Thanks a lot!
goldfries (81 comments)8 October 07
Either replace it with normal text or completely remove it!
I remove what I don’t use. As for the rest, I keep them as it doesn’t save that much server process anyway since servers are very powerful these days and single WP Template Tags won’t hurt the server a bit.
Slevi (73 comments)8 October 07
Doubt the average user even has to bother with this, as goldfries says servers can easily handle it. If your site gets more visitors then yes, these 13 extra php tags do add up. Let’s say 5000 people browsing at any moment that’s pretty much 65000 php statements additionally executed.
But in that case, do you keep something like wordpress needlessly php driven? Or do you simply display a cached version of it?
Elliott Cross (16 comments)8 October 07
Great insight into some of the tags. I especially recommend removing the WP version number from the site, as it does allow everyone to know what version you are using.
One additional thing to add to your site for security is a blank index.php file into the plugins folder. This prevents people from going to your plugin url and seeing what plugins you are using.
goldfries (81 comments)8 October 07
Hehe. Usually those who know how to remove those 13 would add many more other plugins that use up equal or more resources.
For example, Recent posts, Recent comments, Top Commenters, Popular post, Receive E-mail notice, Highlight Author………..
The tags I usually remove are
wp_list_pages()
wp_get_archives()
wp_list_bookmarks()
and a few others in sidebar.php, I think bookmarks is the one for blogroll.
Nathalie (1 comments)8 October 07
Ehm, I don’t agree totally with this article. There are better ways to decrease server loads than this, and it is just meddling with the templates.
First of all, when you’ll get a newer version of the template, all that work will be lost, and also, if you want to make changes (the website name, for exemple), only html-savvy users will be able to dig where the information has to be changed.
I really think Wordpress put it that way for a reason. It must be easy for everyone to use.
Lennot (2 comments)25 January 09
Doing these changes will take about 30 seconds so personally I can’t see a problem with that. Naturally, there are many other ways to speed up one’s blog. However, it is important to avoid unnecessary php requests like these if you’re trying to make a website load faster.
milo (72 comments)8 October 07
Some can be deleted like the WP version tag, but do you really recommend to delete the stylesheet tag?
The usual WordPress user won’t know what to place where,
maybe an example/screenshot of your thoughts would help.
Unsavy Wp users will mess up with this, just take a look in technorati how many of them deleted the title tag.
redwall_hp (134 comments)8 October 07
I was going to write a post on this. Beat me to it again.
Here’s a (partially related) tip for WP users [about get_num_queries() ]:
get_num_queries() is a great tag. If you know what queries are, then I recommend you temporarily put the tag on your blog (in the footer), reload your blog and check the query count, then remove the tag. If you’re blog seems slow after adding a new plugin, it could be querying the database a lot.
adam (18 comments)8 October 07
removing the unncessary code in between the widget call is unnecessary. if the widget function exists, all that code is skipped by the PHP engine, so there’s no load on the server from it. That said, when building my own themes, i usually just stick some dummy text in there (e.g., sidebar 1 goes here).
also, it should be more clear that the wordpress version code, unlike the rest should be DELETED, not replaced with static HTML. that little HTML comment about it being useful for stats, refers to Matt’s statistics of how many users have wordpress installed, not to any stats on your own blog.
pelf (32 comments)8 October 07
I don’t know what those php codes refer to, so I NEVER touched them. I always have the feelings that my blog will crash if I did anything unnecessarily to it.
Yeah, I’m a scaredy cat! LOL.
Ken Dahlin (3 comments)8 October 07
You’re right. These are typically static elements which won’t change once you’ve established your site. It could be the difference between having a site that is up during a spike in hits and one that complains that there are too many SQL connections. Everything adds up. On certain sites I own where I have permalinks which get hit and linked to many times, I’ve converted the pages to 100% static html. This may seem like overkill, but it has saved me the cost of renting another server.
Deaf Musician (5 comments)8 October 07
This is very true, it’ll cut down a lot of processing time. Great tips.
goldfries (81 comments)9 October 07
Slevi said – Let’s say 5000 people browsing at any moment that’s pretty much 65000 php statements additionally executed.
Slevi (73 comments)9 October 07
Keep in mind that on a scale of the entire internet seen John Chow’s blog is nothing either eh
. The 11.295 visitors a day which John Chow reaches isn’t much at all, if you take a look at some of the major torrent trackers they reach about 800.000 unique visitors a day and about 4 million page views a day. And with 4 million a day you’re doing about 50 a second, so 65 additional statements each second. You can understand that sites like those are fully cached
.
Another great example is the Gaia Online forums, which has a record of over 100.000 people online within a period of 15 minutes, since it’s a forum those people will probably view 3 pages at least making up for about 300 pageviews a second.
John Chow might believe he’s a big boy, he might let many readers believe, but in reality the guy has nothing made yet to be really proud of. He falls into nothing compared to the real big sites on the net which make the hundreds of thousands of unique users each day
.
milo (72 comments)9 October 07
∞ Slevi, hehe, seems like you don’t like J.Chow…
but you’re on the right site, he IS a big booble.
Slevi (73 comments)9 October 07
Kinda off-topic but anyways: It’s not so much not liking John Chow since I dunno the guy, but I do think that he thinks too highly of himself at times or at least gives that impression.
Whilst in reality, now what all has he achieved? Something which many of us probably wouldn’t say no against but in the meantime it’s not like he jumps out or anything above the rest.
When it comes to subscribers he’s far from the highest, if you’re talking about monthly income his 20.000 he made last month falls into nothing compared to what the bigger sites are making online and if it comes to traffic there are sites which get within a day what he makes within 2 years.
So I just don’t get why people keep bringing up a guy which essentially just blogs for making money into matters like this. Whenever something is about making money online or high amounts of traffic John Chow tends to get brought up even though he fades away compared to the real big guys out there.
Bit more related to the topic: John chow with his less than 10 visitors a minute wouldn’t really have a need for optimization, taking it for granted that he hosts his site on a dedicated server rather than shared hosting. It should be able to cope with that, but some servers definitely do experience quite a little bit more stress and optimization in these forms definitely would be handy there.
But also for the average user it can be one of those things to prevent your host from kicking you off for that matter. You might perhaps not by yourself knock your server down, but keep in mind that you’re most likely sharing the server with a load of other people. By reducing the php statements used on your site your effectively reducing the overall CPU load which the host undergoes, this in return means that you can keep on hosting on a shared hosting account longer before having to switch to a more expensive form of dedicated hosting.
Madhur Kapoor (12 comments)9 October 07
Thanks for wonderful tip Michael .
Michael Martin (1286 comments)9 October 07
goldfries and Slevi – Thanks for the comments guys, and I know that little tips like this aren’t crucial for most users, but every little helps, and when you’re trying to put off upgrading to that fancy hosting plan for as long as possible, you’re going to appreciate all the help you can get.
Elliot – Good tip for the plugins. That directory is already forbidden on my server, but that may not be the same for everyone.
goldfries – lol – That’s true, but I haven’t yet found a cure for plugin addiction!
Nathalie – The benefits this sort of thing provides are pretty small, so a user that isn’t confident with HTML would be perfectly fine not doing them, as you said.
But for many of us, editing the HTML is no problem (Considering how rarely it needs to be done). The tags are definitely best for out-of-the-box themes, but that doesn’t mean that everyone should keep them that way.
milo – I know what you mean, and there’s no real cure for that. However, I did recommend a pretty easy way of making the changes, and carrying out little tasks like this is one way of getting a little more confidence with HTML (Which all bloggers could use.
)
Redwall – Thanks for the tip. I used the tag the way you suggested when I set up this blog. (At the time I didn’t think to uncomment it though. Woops.
)
Adam – I know that the code is skipped, but why bother having the code bloat at all if it’s doing nothing? Thanks for the explanation of that stats comment though! That has always bugged me!
pelf – lol – Just like so many other bloggers! You’re just right though. Some times it’s just not worth the hassle when you aren’t comfortable with what you’re doing.
Ken – The SQL connections are the main reason I did this in the first place as well. At the minute I’m probably depending largely on WP-Cache to keep me up if I ever get Dugg, at least long enough to pull off the static HTML trick that you used as well. Anything is worthwhile if it keeps you up for all that traffic!
Deaf Musician – One has to hope!
Slevi and milo – I always love the discussions, but please don’t bash another blogger. I imagine they’d be a little ticked to read it.
JC’s isn’t my favorite blog to read either, but considering how popular it is (for a blogger Slevi
), he must be doing something right, and you have to respect the confidence of it all.
Madhur – Glad you liked it.
Sumesh (39 comments)10 October 07
There are two things here, that I understand(correct me if I’m wrong) – PHP is infinitely more faster than MySQL, and the reason why queries should be reduced is because of that. Right?
But, isn’t it better to use less plugins, optimize and minimize your theme more before doing these stuff? If you’re preparing for a digg, good luck. I had this spirit of total optimization, and ended up stripping the theme of all images(except header) which caused a frown among regular visitors.
The fact is, normal traffic rarely needs theme optimization, and sites on shared hosting probably would not withstand diggs/other spikes even with reducing queries – its all down to MySQL and HTTP requests.
Michael Martin (1286 comments)10 October 07
Sumesh – One thing alone isn’t going to save you from a Digg, as you said. But the combination of many small things could well make that difference.
I’m hosted with MediaTemple, and one of their offerings is 2 “bursts” per month. It means that they will up my MySQL resources to stay online during a Digg, so provided I can keep my server processing load low enough as well, then I shouldn’t have any trouble.
It makes taking the few minutes for something like this all worthwhile.
goldfries (81 comments)11 October 07
LOL. I see a sudden J.Chow bashing here.
I’m not his fan either, I’m just using his blog as a comparison – not comparing the ‘Who’s bigger on the Web-O-Sphere’. 
My point – tags aren’t an issue if you consider the capability of servers + the amount of traffic in general.
The plug-ins added usually cause more load than the 13 tags removed anyway. 
I don’t disagree on the lesser load part, it’s just that it’s too minor for anyone to do so unless sparing server resource is really compulsory.
Michael Martin (1286 comments)11 October 07
Your call goldfries. I agree that it’s not a massive change, but I’m definitely one of the “every little helps” crew, so something like this suits me.
SeoTier (1 comments)14 October 07
Excellent! My webhosting account CPU Load are going as high as 4.3% (max. 4.5%)…after using the tips here…my CPU Load is only about 3.2%
Michael Martin (1286 comments)14 October 07
Thanks for sharing your stats SeoTier. Good to see an example of this being effective.
Brian Purkiss (24 comments)25 October 07
There!
I deleted those tags and now I’m actually seeing a better load time!
Thanks!
A2daK (1 comments)7 November 07
I agree with Milo and Adam. Not really a good idea to remove all the PHP tags. Especially if you expect things to update and work as your site develops. Removing unused sidebar widget code is a good thing though.
+++— Will Mac users ever realise that this size of Helvetica looks totally disgusting on IE and not particularly nice on firefox
You Rock Radio (1 comments)7 March 08
Fast is better. This is good advice for sure. A lot of the bloat on some of the sites is even pressing broadband, like Flash heavy sites and stuff. It is mind blowing how many people are still on phone modems, I guess broadbanders take that for granted sometimes. I forgot what the percentage estimated was, like 50% or something.
Rob (34 comments)8 May 08
My site loads a lot faster now that I’ve done the tweaks you outlined here. Thanks, Michael!
Michael Martin (1286 comments)10 May 08
No problem. Glad it worked well for ya Rob.
Vladimir (16 comments)11 June 08
Michael, did you do any benchmarks? If you remove those tags in the best case you will win a couple of queries – this will be approximately from thousandth to hundredth fractions of a second.
Wouldn’t it be better to use a cache (plugin) like Hyper Cache or Super Cache or something like this? In my opinion, performance improvements will then be noticeable.
Vladimir (16 comments)11 June 08
Update: I have looked through the list of all SQL queries executed, it seems that tags removal does not eliminate any of them
Probably need another type of optimization…
tmd (1 comments)25 June 08
Informazioni davvero utili, per molti siti in WordPress sono davvero indispensabili.. Confido molto nell’utilizzo di questi suggerimenti.. Grazie. Good Tip. Thanks
Nihar (2 comments)19 July 08
Very good tip. Will try doing it for my blog…
Brian D. Hawkins (5 comments)20 July 08
Great tips and conversation. What about speed optimization for those of us that would rather pay a Pro? Anyone recommend someone that specializes in WordPress and actually knows what they’re doing? SEO optimization and security issues would be a huge plus too.
I’m not talking about a complete $800 blog design, just tweaking and improving on the theme already being used.
Vladimir (16 comments)20 July 08
Can recommend myself
I’m modest, I know
I specialize in security and MySQL optimization/server tuning.
Is the blog speed really the issue for you? As far as I can tell, it loads rather fast (the home page is almost 1 Meg in size and needs more than 400 requests, which is overkill, although WP gives the content away very fast).
Nihar (2 comments)30 July 08
Great post. I have removed lot of tags that are mentioned in this post. Hope it helps to decrease some server load…
giornale (1 comments)4 August 08
thanks for the tip!
rightyahootr (1 comments)1 September 08
ibm see english home sea england clean
Bogdan Radu (1 comments)6 September 08
I deleted those tags and now I’m actually seeing a better load time!
Thanks!!
WPJunkie (1 comments)30 September 08
Great Tips!
Thanks a lot
chicochuc (1 comments)30 September 08
These tips are great! I can see a big difference now!
thank you!
Ashutosh (2 comments)7 October 08
Nice tips… i am going to implement all of them..
Thanks
Warhammer (1 comments)13 October 08
thanks, that would sure help me save some bandwidth and hopefully faster loading too
john - laptop (8 comments)27 November 08
i agree with your opinon. thank you for this post. very intresting. i like it.
andol (2 comments)2 December 08
nice tips.
batteries (1 comments)9 December 08
Is the blog speed really the issue for you? As far as I can tell, it loads rather fast (the home page is almost 1 Meg in size and needs more than 400 requests, which is overkill, although WP gives the content away very fast).
athul (1 comments)29 December 08
thanks sir . it really benefited & prevented the php processing for headers & made into simple html which can be edited
thank may god bless u
Ana (6 comments)1 January 09
Great tips. Now I hope that does not mess anything up on my blog. Thanks
wombat (3 comments)12 January 09
ahhh, this is just the sort of geeky stuff that i love, great post. Who the f* is that Chow dude.
sorry couldnt resist … cheers
TutorialCompiler (5 comments)15 January 09
Deleting them will make the load lower but then it will have a negative effect on the SEO
zamakh (1 comments)27 January 09
thanks for the tips really helpful especially for those how use free web hosting, like me
Free Download (3 comments)1 October 09
Really great tips you have here.
This is usefull not only for those who use free hosting but also for shared hosting user to avoid their account get suspended because consume too much server resources.
Dean Hamack (1 comments)28 January 09
Good tips Michael. I just got done building a WP theme and stripped a lot of junk out. I didn’t even think about replacing some of these functions with hardcoded ones.
Internet Marketing Dorset (1 comments)28 January 09
Thanks for these great tips. Anything that reduces the load on the server and the speed my website loads has got to be a good thing!
However, I guess it’s important to use caution when deleting stuff in case it effects function elsewhere on the site – having said that, just add it back in but keep a log of what you’ve removed
Preethi (2 comments)25 February 09
This is a great post for all who use wordpress themes.
TomsTricks (4 comments)5 March 09
Great post…….
This is very helpful to bloggers ,who use free wordpress templates.
Evan (4 comments)17 March 09
Wow I never would have thought about removing those tags, I need to go search my template tonight and see if anything is there that shouldn’t be. Another great post my friend.
Student Athlete (1 comments)20 March 09
Thanks for the tips!
Everyday seo (1 comments)10 April 09
thanks for the great tips, actually i came searching from ” how to delete wordpress tag” but landed up here, anyway great information.
if you can come up with how to delete the tag on wordpress, i would greatly appreciated.
Cralietticinc (1 comments)17 April 09
nice, really nice!
Dave (15 comments)27 April 09
Really informative and helpfull. Even small things do matter.
Mukarram (1 comments)30 May 09
Thanks alot…but i have a question that won’t it affect the content of the page….????
Isn’t it important tags to run our theme correctly n perfectly ????
Atul (2 comments)1 June 09
gud info Thanks for sharing
Atul’s Latest Post: Murphy’s Laws on Girls
Pallab (2 comments)10 June 09
Nice post, but would have been more useful if you had mentioned what each tag’s purpose is or linked to the relevant page on codex.
Pallab’s Latest Post: Google vs Bing vs Yahoo : Find out Who is the best with Blind Search
j4p4n (1 comments)15 June 09
thx for those great tips. i replaced even more entries by using the really static expressions
.-= j4p4n´s last blog ..Umbauteil: Fußrasten =-.
Adam (18 comments)27 June 09
wow… thanks a lot for this post, very helpful to my blog.
Frumusete (1 comments)1 July 09
Thanks, very helpful form me
.-= Frumusete´s last blog ..Frumoasa si fericita – Reguli sanatoase pentru frumusete =-.
Pam (2 comments)3 July 09
Total score. I was looking for something totally different, but this will help my blog, it’s so slow.
.-= Pam´s last blog ..How To Combat Boot Funk =-.
Atul (2 comments)11 July 09
very useful post thanks
.-= Atul´s last blog ..Friendship Chain Award =-.
Alif Rachmawadi (1 comments)28 August 09
Thanks for the information. It makes my theme less flexible but faster
Jim Hutchinson (1 comments)2 September 09
The bloginfo(’name’) and bloginfo(’description’) should be left there if you periodically change the blog name and/or description.
For those who want to know the meanings of the rest of the functions, they are:
* language_attributes() defines the page type (letter) and language (en-US) for the page
* bloginfo(’html_type’) and bloginfo(’charset’) define the content type (text/html) and character set (UTF-8):
* bloginfo(’name’) show the name of your site
* bloginfo(’version’) shows which WordPress version is installed
* bloginfo(’stylesheet_url’) is a link to your stylesheet
* bloginfo(’rss2_url’) is your RSS (news) feed URL
* bloginfo(’pingback_url’) is the URL for others to ping back to your posts
* bloginfo(’stylesheet_directory’) shows the directory your stylesheet is in
* bloginfo(’description’) The slogan or description of your site
* bloginfo(’comments_rss2_url’) the URL of the RSS feed for your comments
* get_num_queries() is the number of database queries it took to generate this page
* timer_stop(1) or timer_stop(0, 3) is the number of seconds the script is allowed to compiled the page load stats.
Fatih (1 comments)11 September 09
Thanks for the helpful tips. That said, as a non-php expert, I am bit worried to delete those codes for affecting the blog functionality.
It’d be nice if this removal thing can be made into a plugin. So that it can be deactivated when distract the whole performance of a blog.
Djolhan (3 comments)11 September 09
Thanks for the tips. Article Twitted
Carl (3 comments)13 September 09
meta name=”generator” seems to be loaded by wp_head(); . Where can this be edited or is it part of the core WordPress files ?
duniacyber (1 comments)15 September 09
This is a great tips for blogger. Thank you
Udegbunam Chukwudi (4 comments)16 September 09
Harcoding these tags really helped speed up my blog immensely coupled with the fact that I switched a light theme. With a cache plug-in, the speed has been amazing but unfortunately I’ve decided to hide ads from my regular visitors so I can’t use a cache plug-in any longer.
Udegbunam Chukwudi (4 comments)16 September 09
Hardcoding these tags really helped speed up my blog immensely coupled with the fact that I switched a light theme. With a cache plug-in, the speed has been amazing but unfortunately I’ve decided to hide ads from my regular visitors so I can’t use a cache plug-in any longer.
zplits | what's the latest? (4 comments)16 September 09
thanks for the great tips.
@Carl, in wordpress 2.8+ you can find the
meta name=”generator” under your root directory e.g sitename/wp-includes/general-template.php
1. open wp-includes folder and look for general-template.php(v 2.8+)
2. paste this code ” remove_action(‘wp_head’, ‘wp_generator’); ” before ?> (end tag of <?php)
3. save and check your source code. Enjoy…
I hope you find it useful.
Carl (3 comments)16 September 09
@zplits before ?> is outside of a function, how can it work? BTW, aren’t these files part of the WP distribution, meaning that the changes will be overwritten at the next update?
zplits | what's the latest? (4 comments)17 September 09
Hi sir Carl, yeah it is outside the function. It works sir because the add_action function in wp will be overwritten by the remove_action function found at the last line of general-template.php.
Here’s my other website that hides the wordpress version. You can check it out at http://www.ioacjci.org. View the source code so that you’ll see.
Here’s a couple of code that’s inside my general-template.php for http://www.ioacjci.org
function get_the_generator( $type ) {
switch ($type) {
case ‘html’:
$gen = ”;
break;
case ‘xhtml’:
$gen = ”;
break;
case ‘atom’:
$gen = ‘WordPress’;
break;
case ‘rss2′:
$gen = ‘http://wordpress.org/?v=’ . get_bloginfo_rss( ‘version’ ) . ”;
break;
case ‘rdf’:
$gen = ”;
break;
case ‘comment’:
$gen = ‘‘;
break;
case ‘export’:
$gen = ‘‘;
break;
}
return apply_filters( “get_the_generator_{$type}”, $gen, $type );
}
remove_action(‘wp_head’, ‘wp_generator’);
?>
Carl (3 comments)20 September 09
@zplits works fine. In fact, I needed to flush the cache to get proper operation.
BTW, I came accross a webcast where Google’s Matt Cutts suggests WordPress removes the generator tag, let’s hope the WordPress team will follow these recommandations.
zplits | what's the latest? (4 comments)21 September 09
Hi Sir Carl, wow! glad it works smoothly…oh yeah? that would be nice if the future releases will remove the wp version tag. We’ll see about it in the next updates
tugla (1 comments)5 October 09
Thank you for sharing. I wish you success.
Bestseller (2 comments)8 October 09
These tips will definitely speed up your page load.
I’ve try it myself and it works.
Thanks for the tips
Greg (5 comments)30 October 09
Hi, i’m french and it worked fine for my blog about Geeks and literature. Thanks for your post.
Cell phone tracking (4 comments)16 November 09
Does it really work? I am concerned about the load of my blog, thanks in advance.
vivek bandebuche (1 comments)25 November 09
very usefull post can you similarly tel about the blogger
web collaboration (1 comments)9 December 09
Very informative posts, keep on sharing more informative posts like this. Keep up your good work, eagerly waiting for your next post.
Fred (1 comments)27 December 09
what’s about the really static plguin: http://wordpress.org/extend/plugins/really-static/ ?
jack (8 comments)25 January 10
is it recommended to store repeating functions results in variables?
For example, if I have the_title() or the_permalink() functions appearing more than once in my index.php.
Will it be faster if I type and then echo $title1?
Vladimir (16 comments)25 January 10
>> Will it be faster if I type and then echo $title1?
Yes. You’ll save on several function calls.
jack (8 comments)25 January 10
thanks. so I assumed right that WP doesn’t cache query results by default
Vladimir (16 comments)26 January 10
I am afraid no. WordPress does cache query results but it does not preserve them across the sessions.
WordPress cache is implemented in /wp-includes/cache.php.
Regarding the_title(): when you call the_title() function, WordPress invokes get_the_title(), then get_post() (which takes the post from its internal cache provided it is not the first call to get_post()), apply_filters(). apply_filters() itself is not a simple function.
So when you save the result of the_title() to a local variable, you definitely save CPU cycles
jack (8 comments)26 January 10
You said “it does not preserve them across the sessions”. So I understand that in the same session it does save them.
Assuming I’m in the same loop iteration (ans session of course), calling the_title() function twice will bring the same result.
Then how come these results aren’t cached?
Vladimir (16 comments)26 January 10
> You said “it does not preserve them across the sessions”.
Yes. To clarify, I meant not a PHP session (session_start() et al) but a HTTP request.
> Assuming I’m in the same loop iteration (ans session of course), calling the_title() function twice will bring the same result.
Yes. Doesn’t it? ( One exception is when a plugin installs its own filter for “the_title” hook and returns “random” data every time that hook is called).
> Then how come these results aren’t cached?
They are. If they weren’t you would see a query like “SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND wp_posts.ID = POST_ID_HERE AND wp_posts.post_type = ‘post’ ORDER BY wp_posts.post_date DESC” every time you call the_title().
jack (8 comments)26 January 10
thanks man,
sorry for harden this issue, but if they ARE cached than in this case saving the result of the_title() to a variable will not improve speed…
Vladimir (16 comments)26 January 10
> sorry for harden this issue, but if they ARE cached than in this case saving the result of the_title() to a variable will not improve speed…
The result of the database query IS cached. That is, in the chain “the_title() -> get_the_title -> (get_post(), apply_filters() -> [all filters hooked the_title])” only get_post() part is cached.
WordPress will still call get_the_title(), get_post() (get_post() will test three conditions and perform two assignments), then get_the_title() will perform two assignments, test at least one condition and call apply_filters. apply_filters() itself can call a lot of functions. Then the_title() will perform two assignments, two concatenations (they will result in memory allocations) and test two conditions.
Every call to wp_title() takes ~0.0002 seconds on my server (Intel Core2 Quad CPU Q9550 @ 2.83GHz) with PHP opcode optimizer installed (compared with 0.00074 to issue a query to get the post). It takes *much more* time than $title = the_title(”, ”, false) and reusing $title later.
I do realize that saving 0.0002 seconds seem funny, but it allows to save you more than the Rule #3 (bloginfo(‘charset’) — it took almost 10 times less in my server — only 0.00003 sec).
Quoting myself, if you want significant performance improvements, use any caching plugin.
jack (8 comments)26 January 10
Thanks a lot, it’s clear now
Belajar Ngeblog (1 comments)27 January 10
Hey, thanks for your tips for optimizing wordpress load.