Make WordPress Core

Opened 17 years ago

Closed 16 years ago

#4803 closed enhancement (fixed)

WordPress should be inserting its generator tag via the wp_head hook

Reported by: jeremyvisser's profile JeremyVisser Owned by: westi's profile westi
Milestone: 2.5 Priority: low
Severity: trivial Version: 2.3
Component: Template Keywords: has-patch 2nd-opinion
Focuses: Cc:

Description

This is a legacy behaviour carried on from the dark ages of WordPress:

<meta name="generator" content="WordPress <?php bloginfo('version'); ?>" /> <!-- leave this for stats -->

...which is included in every header.php of every WordPress theme in every WordPress blog.

Don't you think a hook could be used instead?

function wp_vanity() {
    ?><meta name="generator" content="WordPress <?php bloginfo('version'); ?>" /> <!-- leave this for stats --><?php
}

add_action('wp_head', 'wp_vanity');
add_action('admin_head', 'wp_vanity');

I realise it might be a bit impractical, seeing as though doing it, and loading up an old theme would result in duplicate tags, but does everyone agree it's more 'elegant'?

Attachments (1)

wp_vanity.patch (2.3 KB) - added by Viper007Bond 17 years ago.
Rolled into a patch with slight modifications

Download all attachments as: .zip

Change History (22)

#1 @Viper007Bond
17 years ago

Yeah, I've always wondered that myself. This would save the theme author trouble and ensures that it's added by default to all blogs/themes and correctly at that.

It'd also be a lot easier for users to remove that from their header (for whatever reason they deem) as you could just use a mini-plugin to remove the hook rather than editing the theme.

I do foresee complaints now though from those who don't want that tag in their header, but as said, a simple plugin would handle it.

@Viper007Bond
17 years ago

Rolled into a patch with slight modifications

#2 @Viper007Bond
17 years ago

Wasn't sure as to where to add the function (I added it near the bottom of functions.php), so feel free to move it to a better file if need be.

#3 follow-up: @JeremyVisser
17 years ago

Nitpick: Use single quotes in the wp_vanity() function, for performance. :)

#4 @JeremyVisser
17 years ago

One other question I have:

Is having more than <meta name="generator" /> bad? Obviously, if what I'm suggesting were implemented, there would be a lot of themes that have the generator hardcoded in them, resulting in duplicates. Is it non-validating or evil?

#5 in reply to: ↑ 3 ; follow-up: @Viper007Bond
17 years ago

Replying to JeremyVisser:

Nitpick: Use single quotes in the wp_vanity() function, for performance. :)

A line break was needed at the end, so I didn't want to do this:

echo '<meta name="generator" content="WordPress ' . get_bloginfo('version') . '" />' . "\n"; 

That's personally what I do in my own plugins, etc. but I believe WP coding standards dictate doing it the way my patch does, but I could be wrong.

As for validity, I wondered that myself. W3C validates it as being okay.

#6 @westi
17 years ago

  • Keywords commit has-patch added
  • Milestone changed from 2.4 (future) to 2.3 (trunk)
  • Owner changed from anonymous to westi
  • Status changed from new to assigned

+1 - Make writing themes simpler.

#7 in reply to: ↑ 5 ; follow-up: @Otto42
17 years ago

Replying to Viper007Bond:

Replying to JeremyVisser:

Nitpick: Use single quotes in the wp_vanity() function, for performance. :)

A line break was needed at the end, so I didn't want to do this:

Could have done this:

function wp_vanity() {
?><meta name='generator' content='WordPress <?php bloginfo('version') ?> ' />
<?php
}

I'm not sure how much improvement that would be performance-wise though. Just saying, is all. ;-)

#8 in reply to: ↑ 7 @Viper007Bond
17 years ago

Replying to Otto42:

Replying to Viper007Bond:

Replying to JeremyVisser:

Nitpick: Use single quotes in the wp_vanity() function, for performance. :)

A line break was needed at the end, so I didn't want to do this:

Could have done this:

function wp_vanity() {
?><meta name='generator' content='WordPress <?php bloginfo('version') ?> ' />
<?php
}

I'm not sure how much improvement that would be performance-wise though. Just saying, is all. ;-)

This is true, but stepping in and out of PHP for such short time and for simple code seems not worth it.

#9 follow-up: @rob1n
17 years ago

I'm -1 for this, mainly because I disagree with what Viper says about how it would be "a *lot* easier for users to remove that from their header (for whatever reason they deem) as you could just use a mini-plugin to remove the hook rather than editing the theme." I strongly disagree. Opening up a theme file in a text editor and taking out one line is a LOT easier than creating your own mini-plugin, or searching for, downloading, installing and activating a plugin that takes out a simple line of HTML output.

It's just one line, which IMO is not worth it to make writing themes "easier", if it's that bad you can just copy and paste it.

#10 @rob1n
17 years ago

  • Keywords 2nd-opinion added; commit removed

#11 follow-up: @Nazgul
17 years ago

There are still a lot of HTML 4.x themes out there which won't like it if we put a self-closing tag in there, because they will fail validation. We'd have to differentiate between HTML and XHTML.

On the other hand, it's "free" advertisement for WordPress, because as it is now, it depends on the theme if they include the generator tag or not.

#12 @rob1n
17 years ago

A bit off-course here, but are there really that many HTML 4 themes? WP outputs self-closing tags by default, and that's hard coded into the core. Unless I've missed something big, it would take either an output buffer filter (clumsy and slow) or changing core files, or, to an extreme point, filtering each output.

#13 in reply to: ↑ 11 @JeremyVisser
17 years ago

Replying to Nazgul:

There are still a lot of HTML 4.x themes out there which won't like it if we put a self-closing tag in there, because they will fail validation. We'd have to differentiate between HTML and XHTML.

There are other more significant places where XHTML markup is hardcoded, and this is really trivial to overcome if you're using a HTML 4.x theme by making a functions.php file like the following:

<?php

remove_action('wp_head', 'wp_vanity');

?>

Can't get any easier than that.

#14 in reply to: ↑ 9 @Viper007Bond
17 years ago

Replying to rob1n:

Opening up a theme file in a text editor and taking out one line is a LOT easier than creating your own mini-plugin, or searching for, downloading, installing and activating a plugin that takes out a simple line of HTML output.

For someone like us, yes, but you try explaining how to open up and edit a theme file, set file permissions, etc. to an extremely novice user. I think uploading a file (which they've already done by installing WP) and hitting activate is easier.

And as Nazgul, this also assures that WP is properly cited as the generator (for stats) and as JeremyVisser said, really easy for theme developers to take it out if need be.

So anyway, yeah, it's not perfect (especially in the short term), but in the long term, I think it's the best solution.

#15 @Otto42
17 years ago

+1 to this.

Having a duplicate generator tag for some themes won't hurt anything in the short term.

And anything that makes theme writing easier should be adopted. I think that quite a lot of the meta tags and such should move into actions/filters in the core. Theme writing is often done by people who don't know much PHP, the more we can take out of themes, the better off everybody is.

As for the self-closing tag thing, isn't <meta ...></meta> valid both in HTML and XHTML? If self-closing is such a big problem for some themes, don't use it.

#16 @JeremyVisser
17 years ago

If I remember correctly, explicitly closing an implicitly closed tag in HTML causes problems.

(Though I may be wrong, and should really be using a validator to back up my statements.) :)

#17 @Nazgul
17 years ago

  • Milestone changed from 2.3 to 2.4 (next)

#18 follow-up: @Otto42
17 years ago

Matt Cutts argued for removing the generator tag entirely at WordCamp 2007. See here (Powerpoint presentation, slide 27 of 28): http://www.mattcutts.com/files/Whitehat-SEO-tips-for-bloggers.ppt

Two thoughts:

  1. Are we actually getting any relevant or useful stats out of this? If not, then it should go away entirely, as it's useless.
  1. Is the version number really necessary? If we get stats that pertain to installed base, wouldn't just content='WordPress' be enough, instead of including the version as well?

-1 on moving it to core without some debate on eliminating it entirely.

#19 in reply to: ↑ 18 @JeremyVisser
16 years ago

Unless Automattic creates a spider and crawls the entire World Wide Web looking for generator tags, I don't think it's actually possible to generate stats based on that tag.

#20 @docwhat
16 years ago

Howdy,

I've got bug #5085 for unifying the user-agent, it'll make this a little easier...

As well as making the plugin to remove the generator easier, too.

Ciao!

#21 @westi
16 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [6195]) Centralise generator generation, move theme generator generation to wp-head hook. Fixes #5085, #4803. props docwhat, Viper007Bond.

Note: See TracTickets for help on using tickets.