WordPress

Posts about using the open source CMS WordPress

Add Enctype To Wordpress Post And Page Forms

27th March 2010 - 2 minutes read time

Whilst creating a small plugin on a Wordpress site I decided not to use the media library as I just wanted to add some small stub images to the content. I created some boxes on the post page using add_meta_box() and added a file input box to them. The only thing is that the post form in Wordpress doesn't have the enctype="multipart/form-data" attribute and so it won't pass file to the $_FILES array in PHP.

It is not possible to add the enctype into the form declaration via Wordpress as there is no hook or action to do this. So the only alternative (rather than hack the source code) is to add the attribute using JavaScript, and as we have JQuery already loaded we can utilise that.

Wordpress Database Changes When Moving Site

27th March 2010 - 5 minutes read time

When moving a Wordpress install from one place to another there are a number of things you must be aware of. If you have created your templates properly you will have used calls to bloginfo('home') rather than using static links, but you will need to update these links to make your Wordpress install work properly.

Once the files are in place, the database connection details have been edited and the database created there are a number of things to alter in the database to make your Wordpress install work.

The most important changes are in the options table. There are two references to your URL in this table that must be altered to stop Wordpress redirecting back to your old site. This must be done via database access as Wordpress will redirect you when you try to login to the stie.

Wordpress Permalinks SEO Best Practice

12th March 2010 - 3 minutes read time

Setting up a permalinks structure in Wordpress one of the things I normally do right after installing a blog, before event getting started on the templates. However, I always seem to forget what to put in the box so I thought I would put this here to remind myself and to go over the best practices on your own site in terms of SEO.

To set the permalinks on your Wordpress install go into Settings > Permalinks and enter the following into the Custom Structure field.

/%postname%-%post_id%.html

This will make a post on your site have a URL something like this.

/this-is-a-new-post-2.html

It is also possible to create a permalink using the category slug by using the %category% option.

parse_url Warning Bug In Wordpress 2.9.2

23rd February 2010 - 3 minutes read time

Whilst setting up a new Wordpress install for a site development I found an odd little issue that would only occur in certain circumstances. My current development platform consists of an Apache server on which I create a virtual host for every development site I need. However, rather than setting a DNS entry for each address I just listen to diferent ports. In this particular instance I used the port 59419.

When the install was complete I was presented with the following error at the top of every admin page.

Wordpress Breadcrumbs

19th December 2009 - 7 minutes read time

I have been playing about with breadcrumb trails in Wordpress recently so I thought I would post the code here in case anyone else finds it useful. The basic idea is to try to find out where the current page is situated within the site. This means checking for pages and categories with their parents. Once we get down to the post level we need to try some things in order to find out where the current post is within the site.

Once the trail array has been filled with items it is looped through and converted into a string.

To use this function put the following code into your functions.php file in your template.

Change Number Of Search Results In Wordpress

27th November 2009 - 2 minutes read time

Wordpress allows administrators to change the number of posts that are printed out on a page at once on the page Settings - Reading. However, this also has an impact on the number of search results that Wordpress will display. In order to keep the size of the home page down many Wordpress admins will reduce the number of articles to two or three. This can instantly make search results with only a few results reach many pages.

To get around this you will need a template called search.php, this is the template that Wordpress will use when printing out the search results. Towards the top of this file (anywhere above The Loop) add the following code.

Wordpress DoS Attack Script Solution

20th October 2009 - 3 minutes read time

There is a script knocking about on the internet at the moment that allows an attacker to run some code that will bring your Wordpress blog to its knees. This will more than likely cause your host to get annoyed as well.

What it does it performs a trackback request to the file wp-trackback.php, but it sends a massive (over 200,000 characters) string that Wordpress will take at face value and accept as a legitimate trackback. The first time this is run Wordpress will write it to the database, but the every time after that it will run a select query to see if the trackback exists. Even though this isn't a legitimate trackback Wordpress will still process it on every request, causing a massive overhead as each large string is processed.

One solution is to simply stop access to the offending file by using an Apache rule in your .htaccess file to prevent all access to this file.

Wordpress 2.8.3 Admin Password Exploit And The Fix

11th August 2009 - 3 minutes read time

A small exploit has been found within the latest (currently 2.8.3) version of Wordpress that can cause any attacker to reset the admin password. The attacker won't be able to see what the password is, and the new password is emailed to you anyway, but it might cause some users to be locked out of their blogs if they can't get access to the email or their email is down. However, it is a real pain so I am writing this blog to allow other bloggers to fix their Wordpress installs.

The Problem

Wordpress allows you to reset the admin password, which some users might want to do. The normal course of events is that the admin user selects that they want to reset their password and Wordpress will email the user a link containing a key. Following this link will reset the admin password. The issue is that it is possible to recreate this link without first sending out the email, which will reset the password. Here is the URL that can be used to reset the password.

Create A Page Of Posts In Wordpress

11th August 2009 - 7 minutes read time

A common practice when setting up a Wordpress blog might be to create a page and display posts in a certain category on that page. This causes some pages to act very much like category pages.

The first step in creating a page of posts is to create a page template that can be used by the pages. Create a file in your template directory called pageofposts.php and put the following comment in it.

Add A Post To Twitter Button To Your Wordpress Posts

4th June 2009 - 3 minutes read time

This is quite a simple thing to do and it is quite easy to add a little link to your Wordpress posts. If the user is logged into Twitter on the web (which isn't all that common with multiple Twitter apps taking over) then when they click on a link they will be taken to their Twitter profile and their status box will contain the text you have set. You won't actually be able to update a users status for them, they have the final control over that, but some users will update their status so it is worth doing.

This is all done through a URL using the status parameter, like this.

http://twitter.com/home/?status=text+to+post

Because this is a URL you will need to encode it properly in order for Twitter to understand it. Using Wordpress you need to put a call to the urlencode() function to encode any string you might want to post.