WordPress Coding Standards

In a collaborative programming environment it is always good to have a set of coding standards that you follow.

Thankfully, WordPress have coding standards which all developers should try to follow.

If you peek at the WordPress source you will notice that (almost) all code follow this standard, which makes it very easy for other developers to read the code.

Take a look at the section discussing shorthand PHP tags, an issue I have written about previously. Space usage is also a very common mistake among developers. The correct space usage can really improve your code’s readability.

Further reading:
Codex: WordPress Coding Standards

Advertisements
Tagged with: , ,
Posted in Best Practices, Intermediate

Custom Post Type Best Practices

I have used Custom Post Types in almost every WordPress project I have worked on since the feature was introduced in WordPress 3.0.

When collaborating with other developers you also come across some common mistakes, mistakes that I’ve also made in the past. So I would like to share some things to keep in mind when using Custom Post Types.

The $post_type should always be singular

The codex does not explicitly say it anywhere, but all the Codex examples use singular names for $post_type. This is probably the most common mistake I see developers make. If you want the new post type’s URL to have a plural word in it, you can specify it in the slug argument.

Use a namespace for your post types

This is something that even I haven’t done. But the codex makes a good point in their own best practices section. A conflict can occur between theme and plugin post types if you use a common word as the post type name and it is not prefixed with a namespace. So for instance if your post type is a product, do not simply name is product but rather yournamespace_product.

Remember the template hierarchy when creating specific post type templates

WordPress template hierarchy is great, so please use it! I have seen cases where developers have created a new page with an associated template where they query for the posts instead of simply using the default template file to create an archive page for example.

From the codex:

In the same way that posts are shown on their own page with single.php, custom post types will use single-{posttype}.php if it’s available.

Same thing applies to archive-{posttype}.php. This visual overview of the template hierarchy is something I keep referring to.

Adding custom columns to the admin can be easy!

Joost De Valk provides these code snippets that can come in handy when working with custom post types. Often you also have custom taxonomies or other meta data linked to your post types which you might want to present in the admin. Great post!

Tagged with: , , ,
Posted in Best Practices

WordCamp San Francisco

This will surely be the event of the year (as far as WordCamp events go).

More information here

Posted in Uncategorized

Oakwood Creative is hiring a front end developer!

The company I work for is currently hiring a front end developer. So if you’re located in Stockholm, Sweden or willing to relocate you should definitely check it out!

We have put together a small site for you turn into HTML as a work sample, which could be fun as a night activity!

More info here:
http://oakwood.se/jobb (English version)

Tagged with: , , ,
Posted in Uncategorized

Remove all “missing” files from a SVN working copy

After upgrading a local installation of WordPress subversion started complaining about missing files, that were deleted during the upgrade.

Since there were a lot of files I searched for an easy way to delete all the missing files at once, and found such a way here.

svn rm $( svn status | sed -e '/^!/!d' -e 's/^!//' )

One of the comments mentions that it doesn’t work with filenames that contains white space, which I haven’t tested.

 

Tagged with: , ,
Posted in Misc

Add your own CSS classes to tinyMCE

The Rich Text Editor (RTE) in WordPress use a JavaScript-library called tinyMCE. It is a widely used library and can be configured in a lot of ways.

WordPress let developers filter the settings to tinyMCE so that it fits your needs.

function mytheme_tiny_mce_before_init($arr){
 $arr['theme_advanced_blockformats'] = 'h2,p,blockquote';
 $arr['theme_advanced_styles'] = 'Leading=leading';

 return $arr;
}
add_filter( 'tiny_mce_before_init', 'mytheme_tiny_mce_before_init' );

function mytheme_mce_buttons($arr){
 return array('bold', 'italic', '|', 'bullist', 'numlist', '|', 'formatselect', 'styleselect', '|', 'link', 'unlink' );
}
add_filter( 'mce_buttons', 'mytheme_mce_buttons' );

These few lines of code changes the buttons in the editor, and also adds a format select and a style select.

From the format select you now can select “Heading 2”, “Blockquote” and “Paragraph”. In the style select you can select “Leading” and your element will get the CSS class leading.

Tagged with: , , ,
Posted in Intermediate
About

WordPress Quick Tips is a blog supplying great tips about WordPress.

We hope to create a great knowledge resource for WordPress developers as well as serving a reminder for all the forgetful ones.

The blog is created and run by Vincent of Oakwood Creative

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 120 other followers

%d bloggers like this: