May 21, 2012

WordPress 2.0.1 still has annoying attribute stripping

stop button Wordpress 2.0.1 still has annoying attribute strippingWhen WordPress 2.0 was released, its aggressive tag attribute stripping caused me a lot of pain. For example, I couldn’t link any image at all using my favorite blogging client, Ecto. I was hoping that the 2.0.1 release would fix this problem.

Well, yes and no

It fixed some-but-not-all of the tag problems. It still strips too much for my taste. I’ve once again added several attributes back into my wp-includes/kses.php file.

The changes I’ve made are:
'div' => array ('align' => array (), 'class' => array (), 'id' => array(), 'style' => array()),
'img' => array ('alt' => array (), 'class' => array(), 'align' => array (), 'border' => array (), 'height' => array (), 'hspace' => array (), 'longdesc' => array (), 'vspace' => array (), 'src' => array (), 'title' => array (), 'width' => array ()),
'span' => array ('class' => array (), 'id' => array(), 'style' => array()),
'p' => array ('align' => array (), 'class' => array (), 'id' => array(), 'style' => array()),
'tag' => array(), 'tags' => array(),

You can download a pre-tweaked kses.php here: wp2-kses-fix.zip
[tags]Wordpress,Wordpress2,Wordpress2.0.1[/tags]

WordPress title suffix plugin

adapter Wordpress title suffix pluginI read some research recently which seems to show that keywords matter to search engines in your site’s “title” tag. Not only that, but position matters. Preferably your page title should precede your site title.

Unfortunately WordPress is coded to make that sort of ugly. If you simply reverse the wp_title and wp_bloginfo(‘name’) calls, you get ugliness in two ways. If what you want is “keyword – sitename”, then you have to live with the default title for your site looking like “- sitename”. Ugly. Then if you are on a titled page, you get “» keyword – sitename”. I don’t know about you, but I think that’s ugly too.

So, enjoy my tiny little WordPress plugin. It will strip out the leading “»” and will not put the dash in unless there is something preceding it. I’m no PHP god, but that was both easy and fun, due to the “hook” system WordPress implements so nicely. You’ll still have to reorder your themes to have “wp_title” listed before the sitename, but at least it will look prettier now.

Download: wp-title-suffix.zip

[tags]wordpress2,wordpress,plugins,seo[/tags]

Related posts

Solving WordPress 2.0 External Posting Errors

Since upgrading to WP2.0 I had not been able to use my favorite Weblog editor Ecto to do any posts which contained any inline tags, such as div or span classes. Also, it had been stripping the meat of Image tags. This was playing hell with my Technorati tags and, well, with how I like to blog.

Looking at the Ecto console, I saw that it was actually WP which was refusing to take the tags. With that bit of information, I rapidly zeroed in on the problem.

Solution

Edit your wp-includes/kses.php file, add the tag attributes you want.

I changed or added the following:
'div' => array ('align' => array (), 'class' => array (), 'id' => array(), 'style' => array()),
'span' => array ('class' => array (), 'id' => array(), 'style' => array()),
'p' => array ('align' => array (), 'class' => array (), 'id' => array(), 'style' => array()),
'tag' => array(), 'tags' => array(),

You can download the kses.php file with my fixes, if you like.

Now, everything but the img uploads is working as it should. I’ll figure that out and post the solution soon.

Update: 15 minutes later

To make images work, simply make sure you close the tag, and put a space after the src.

Bad:
<img src=”http://example.com/test.jpg”>
<img src=”http://example.com/test.jpg”/>

Good:
<img src=”http://example.com/test.jpg” />

Thanks go to Doncha for the img tag tip.

Technorati Tags: ,