Jul 19 2009

EzGz: WordPress GZip Plugin

By default, WordPress (at least in the current generation, 2.8) does not enable any kind of compression on its output. Some plugins, like WP Super Cache, add gzip compression, but that’s an awfully big plugin if all you want is compressed output.

So I wrote EzGz this afternoon. It is, by far, the simplest plugin I’ve ever written. The actual source is probably two orders of magnitude smaller than the comments (plugin details and the license).

All EzGz does is enable the built-in PHP gzip/deflate handler. This does require output buffering, so it’s not right for everyone. Some themes or other plugins may already do this.

I’ve tried using the zlib.output_compression ini setting, but on my server, with zlib working otherwise correctly, the setting had no effect. So I stuck with the output buffering.

You can download it, or check it out of svn, then turn it on and see if it works.


Jul 2 2009

WP: Better Search Widget 1.1

Better Search Widget 1.1 is a significant upgrade to Better Search Widget that adds new features and fixes an old bug with internationalization.

Features

(New features in bold.)

  • Optional default value.
  • Optional, custom widget title.
  • Optional onfocus and onblur listeners.
  • Optional, customizable focus and blur colors.
  • Custom button value.
  • Custom field size.

The built-in search widget has only one of these features, the optional, custom title.

Onfocus and Onblur

In order to use the blur and focus colors, you must enable the onfocus and onblur event listeners. In order to use the listeners, you must specify a default value (otherwise none of this makes sense). Here’s an example:

Bug Fixes

A pretty serious typo meant that none of the internationalization code worked correctly. This has been fixed, and en_US, en_GB, and fr_FR localizations are available. de_DE is coming. If you’d like to translate, there is a .pot file included in the languages directory.

License

Better Search Widget is released under the MIT License. If you use it, or have suggestions for new features or bug fixes, let me know!

Getting It

You can download Better Search Widget 1.1 now in a Zip file. Or, to save yourself some trouble,  you can check it out of Subversion from

svn co svn://jamessocol.com/better-search-widget/tags/1.1.0 ./better-search-widget

(Run that in your wp-content/plugins directory.) Subversion will make it easiest to upgrade later.

Roadmap

Soon, though probably not today, I will be releasing Better Search Widget 2, which will take advantage of the new Widget API in WordPress 2.8. This will add support for multiple instances of the widget, but will require at least WordPress 2.8. You should upgrade, anyway.


Jul 1 2009

Widget l10n

I spent some of today working on bringing a couple of WordPress widgets up-to-date (Better Search and Most Comments) only to discover there is a new widget API. I guess I haven’t been paying attention.

I’ll probably start some 2.0 branches tomorrow to take advantage of the new API. I wish I didn’t know how many people don’t keep their WordPress installations up to date, so I wouldn’t care about backwards compatibility.

At least both widgets got nice new, and functional, internationalization (i18n) code and new localization (l10n) files.

And BSW got a good feature update, incorporating some suggestions from Marco Jung, who is also, kindly, doing a German localization, and a few of my own. The built-in search widget has stepped up it’s game, and fixed the thing BSW was originally designed to fix (no widget title) so I have a higher bar to clear to justify the name “Better Search Widget.”

I’ll write up the new features tomorrow.


Sep 4 2008

WP Plugin: Better Search Widget

Today I upgraded from WordPress 2.3.3 to 2.6.1. I’m such a late adopter sometimes.

I had to go through and repeat a few hacks. For example, 2.3.x didn’t allow you to do get_sidebar($name), so I’d hacked the “get_sidebar()” function. And I replaced the still-broken Atom feed reading widget with James Wilson’s Google Reader Widget.

Then I finally got fed up with the default “Search” widget, which doesn’t look like the other widgets at all (no title), so I started hacking into that one. Then I realized “why hack, when I can extend?”

So, here it is, Better Search Widget.

All it does is add a search widget with a customizable title, submit button, and field size. Quick-and-useful. You can see the results in the sidebar.

If you decide to use it, leave a comment and I’ll check out your blog.


Apr 21 2008

Skinning(/Leatherworking)

I’m (finally) working on the new theme. It’s obviously a work-in-progress, so just appreciate the effort for now.

I’m starting with the default WordPress theme by Michael Heilemann. I’m not going to lie: I really dislike this particular theme. Continue reading


Dec 26 2007

WordPress Plugin: Insert Ad Code

I wanted a way to generate more revenue off my WordPress blog. A lot of sites use square ads embedded after the first couple of paragraphs of their articles, and I thought this would be perfect for my post pages, which don’t show the WordPress sidebar. But I couldn’t find a way to do it, so I wrote Insert Ad Code to do it for me.

Insert Ad Code is a pretty simple WP plugin: it inserts some HTML into your posts. It’s very easy to install and pretty easy to use.

Installation

To install Insert Ad Code, all you need to do is unzip or upload the insert_ad_code directory to your wp-content/plugins directory. Then activate it through the Plugins page of the site admin. That’s it, everything’s ready to go.

Using Insert Ad Code

Before you start using Insert Ad Code, you’ll need to have some kind of ad to display. I use the Openads Ad Server on my site, but you could also use Google AdSense or any other add server.

Important Note: Insert Ad Code does not rotate ads by itself. It inserts the same code every time its used. If you only have one advertiser at a time, this might be fine for you, otherwise, you’ll need to use some external program to rotate the ads.

For now, I’ll assume you’re using AdSense. Go get the AdSense code from Google. I recommend either a box ad (250×250) or some kind of horizontal ad (banner or half-banner, depending on your theme), since these will get inserted directly into the post.

For example, your code might look something like this:

<script type="text/javascript"><!--
google_ad_client = "pub-xxxxxxxxxxxxxxxxx";
//Inserted into Articles
google_ad_slot = "xxxxxxxxxxxxxxx";
google_ad_width = 250;
google_ad_height = 250;
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

Copy the code for your ad and visit your WordPress Options page. Go to the Insert Ad Code options. Paste the code into the text box at the bottom. Click Update Options ».

Customizing Insert Ad Code

Now you have a couple of choices here. The first option (Enable Insert Ad Code) will turn the plugin on or off (turning it off does not disable it in WordPress). This makes it easy to stop inserting ads if you need to.

The second (Use <!–more–> or Custom Tag) and third (Custom Tag) options let you decide where Insert Ad Code will put the ads. The default option is to insert the ads right by the <!–more–> tag. You could also use a custom tag (I’d still recommend using an HTML comment, just in case you turn off Insert Ad Code later).

I use the <!–more–> tag for four reasons.

  1. I don’t want to break up very short posts with ads.
  2. I don’t want to go back and insert a new tag into all my old posts.
  3. I want the ads to appear once, after a couple of paragraphs, just like the <!–more–> tag.
  4. I want the tag to be easy to add via the WordPress editor.

If you do feel like using a custom tag just change the settings, include that tag in your posts, and watch the magic happen.

License

This plugin is “show me”-ware. If you decide to use it, please let me know so I can see my handiwork in action! Other than that, it’s GPL.

Download Insert Ad Code

Now that I’ve been talking it up so much, you probably want to download the plugin.

Update! You can now check Insert Ad Code from SVN to get the latest build.
svn://jamessocol.com/insert_ad_code/trunk

You can check out the tags directory for specific versions.

Feedback

Please leave a comment or email me if you use Insert Ad Code, or if you try to use it and hate it, or if it kills your dog. I’m not going to bring your dog back to life, but I’d love to hear your feedback.

Update (Again)! If you’d like to help me translate Insert Ad Code, version 1.1.0 and above contain .po files. If you’re bilingual, translate it and send me the .po and .mo files, and I’ll include them (with credit, of course!)