Using Custom Fields for meta tag content

A fellow member of the SitePoint Forums asked how he could put meta description and meta keywords tags into his page's head. How can I use Custom Fields for meta description/keyword content?

I had never used Custom Fields before, but short of using a plugin to insert the meta tags, it seemed that using them would be the next best option.

Adding Custom Fields was easy enough to do in the Admin edit panel. And finding example code in the Codex was easy enough too. But the examples are for using the custom fields within a page's content, not in it's head.

Experimenting in my localhost test blog, I soon discovered that for the get_post_custom function to work it needed to be inside the Loop. Or more specifically, in this case, a Loop. Which makes obvious sense considering post_custom belongs to a post so it needs to be inside the Loop where the post information is available, :d'oh:

Custom Fields can be named just about anything, so I used:


for field names and entered some text for testing purposes.

Then in my theme's header.php file under the title tag I inserted

if (have_posts()) : the_post();
$custom_fields = get_post_custom();
$custom_meta_description = $custom_fields['meta-description'];
$custom_meta_keywords = $custom_fields['meta-keywords'];
if ( !empty($custom_meta_description[0]) )
	echo "<meta name='description' content='" .
	 htmlentities($custom_meta_description[0]) . "' />\r\n";
if ( !empty($custom_meta_keywords[0]) )
	echo "<meta name='keywords' content='" .
	 htmlentities($custom_meta_keywords[0]) . "' />\r\n";

Admittedly hackish, and not the optimal way to get this accomplished, but it is easy enough to do and it works.

WordPress Functions 3.0

A plugin searched 269 PHP files, of which 167 contained classes and functions, and found 168 classes and 3,856 functions.

WordPress version 3.0 has significant differences from earlier versions, perhaps most importantly, multisite support.

The PHP Classes and Functions of WordPress 3.0

* Note *
The list does not include any found in plugin or theme files as these will differ from blog to blog. Nor does it differentiate between "stand alone" functions and functions that are members of a class, such as the Snoopy functions.

If you know of any Core functions that are not in the list, please leave a comment so I can modify the regex used to find them.

Technorati Tags: , ,

Error Reporting Plugin Release Candidate

The first version of the Error Reporting plugin became available in March of 2007. Since then there have been a few changes, most notably, the Ping Error with dashboard widget feature, and an Auto Delete of old error log files feature that has been added in response to Alex Kah's suggestion. And thanks to Frank's comment, a deprecated parameter has been replaced. It wouldn't do to have the Error Reporting plugin causing errors now would it?

Some known issues remain. With WordPress' switch to SimplePie, many E_STRICT errors are thrown as a result of WordPress maintaining support for PHP 4. In order to avoid Internal Server errors, the Error Reporting plugin does not handle any E_SRICT errors from the class-simplepie.php file. Until WordPress no longer supports PHP 4, this can not be changed.

Perhaps more troublesome is reading the log files under certain configuration settings. Because every error changes permissions to read from, and write to, the error log files, and then makes them secure, if an error occurs after the permissions have been set to "NOT secure" to allow reading, they still can't be accessed. This requires temporarily reconfiguring the Error Reporting plugin's settings so as to not include whatever is causing the error.

TO DO: Find some way to temporarily disable the Error Reporting plugin while the permissions are "NOT secure" and then restore the configuration when made "secure" or after a period of time.

Possible solution: Adding another option or two, i.e. "user's preferred settings" and / or "current settings" to hold configuration settings. This could be "set" by a plugin user and could then later be used to reset the settings after they have been changed.

Alex Kah also suggested that the Error Reporting plugin have a way to send email notifications to an address other than the blog's "admin_email" address. I am hesitant to make this too easy to do, as it would introduce the potential of sending many, many, many, many, many emails to a wrong email address. It's one thing to accidentally flood your own inbox, quite another to flood someone else's. Not to mention sending information about your blog that may create a security risk.

TO DO: Seriously consider adding a "send email notifications to" feature.

Possible solution: As it is now, the plugin can be hacked to hard code an email address in place of the "admin_email". This could be replaced with a CONSTANT that could be defined near the beginning of the script to make changes easier. Or an option could be added so hacking wouldn't be required.

Any comments regarding these issues, or other suggestions, are most welcome and will be greatly appreciated.

For more information please visit the Error Reporting Plugin page.
This post is for comments, suggestions etc. If you need support for the plugin
- please visit the Mittineague Forums (registration required to post).

WordPress Functions 2.9

A plugin searched 252 PHP files, of which 161 contained classes and functions, and found 174 classes and 3,677 functions.

WordPress version 2.9 no longer has these 7 files:


and now has these files:


Many previously existing files have a new function or more. Several files no longer have a setDefaultPermissions function, and several others now have a _normalize_tag function.

Some of the files containing new functions include:
wp-includes/media.php which has another class and 25 more functions.
wp-includes/pomo/streams.php which has 2 more classes and 12 more functions.
wp-includes/pomo/translations.php which has another class and 11 more functions.
wp-includes/kses.php which has 4 more functions.

Also of interest is the replacement of SimplePie version 1.1.3 with SimplePie version 1.2, which has 4 more classes and 37 more functions than the previous version.

The PHP Classes and Functions of WordPress 2.9

* Note *
The list does not include any found in plugin or theme files as these will differ from blog to blog. Nor does it differentiate between "stand alone" functions and functions that are members of a class, such as the Snoopy functions.

If you know of any Core functions that are not in the list, please leave a comment so I can modify the regex used to find them.

Technorati Tags: , ,


The wp-includes/post.php file contains 4 error suppressors. The wp_save_post_revision function contains the line

if ( @constant( 'DOING_AUTOSAVE' ) )

When it is defined, it is when the wp-admin/admin-ajax.php file's _wp_ajax_delete_comment_response function defines it as boolean true. This is the only other place where the DOING_AUTOSAVE constant can be found within the WordPress core files.

Because I can see no reason why this couldn't be written as

if ( defined( 'DOING_AUTOSAVE' ) && constant( 'DOING_AUTOSAVE' ) )

I left a Trac Ticket, but as of yet, it is still unanswered.

UPDATE: As of WordPress 2.9 this E_WARNING error has been fixed. The line is now

if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
Technorati Tags: ,