Code snippets

This is the archive for Code Snippets - little bits of PHP to do interesting things in WordPress. By their very nature, Code Snippets tend to be short, sharp and to the point, and deal with one specific issue. More detailed tutorials and articles covering web site development using WordPress are filed under Web Development.

Transposh Translation Plugin WP header image

Genesis – Prevent Transposh from translating Site Description

Tutorial and code snippet to prevent Transposh WordPress Translation plugin from translating your Genesis framework SEO Site Description, using the genesis_seo_description filter.

Studiograsshopper code snippet

Genesis Breadcrumbs – Custom Post archive crumb is not clickable

You are using the excellent Genesis Framework from StudioPress, you have set up a Custom Post Type but – when viewing a single Custom Post Type post – you notice that the Genesis Breadcrumb trail shows the Custom Post Type as plain text, rather than as a clickable link. This quick tutorial shows you how to fix this.

Transposh Translation Plugin WP header image

Genesis – Prevent Transposh from translating Site Title

Tutorial and code snippet to prevent Transposh WordPress Translation plugin from translating your Genesis framework SEO Title, using the genesis_seo_title filter.

Ducati image

WordPress – List all image sizes in Media Uploader

A handy code snippet to show how to use the new WordPress 3.3 image_size_names_choose filter to display all image sizes (ie those created by add_image_size() as well as the default image sizes) in the Media Uploader.

Ducati image

Remove WordPress default media image sizes

A follow up to my add_image_size() demo article, showing you how to stop WordPress from automatically creating all or any of the default image sizes (thumbnail, medium, large) during the media upload process.

More fun with comments

WordPress $current_screen variable for admin screens

The $current_screen global variable contains information useful for plugin and theme authors to find out which WordPress file is generating the current admin screen. This article gives an overview of the $current_screen variable and how to access it.

iStock_000001952705XSmall

Customising the_excerpt

How to add “read more” links and change the length of the text generated by the_excerpt() Wordpress function. Examples for both Auto and Manual excerpts.

iStock_000001952705XSmall

WordPress 3.0 action hook contextual_help

Here’s an update to the previous article on adding contextual help to Wordpress plugin options/settings pages, which describes how to maintain compatibility with the new $screen object in Wordpress 3.0.

More fun with comments

Dynamic category menu highlighting for single posts

A tutorial to show how to implement dynamic menu highlighting of Wordpress category menus when viewing single post pages.

Studiograsshopper code snippet

Limiting WordPress Post Revisions

How to limit the number of Post Revisions automatically saved by Wordpress, or suppress them altogether, together with how to delete existing Post Revisions from the Wordpress database.

Studiograsshopper code snippet

WordPress action hook contextual_help

How to use the Wordpress Action hook “contextual_help” to add useful Help or other notes to a plugin’s Settings page. Although of greatest use for plugin developers, it could also be used by theme developers to add additional Help info to customised Post/Page Edit screens.

Studiograsshopper code snippet

WordPress Editor – disabling wpautop()

How to disable wpautop() and take control of your paragraph and line-break tags when using the Wordpress Post/Page Editor.