Adding Features to WordPress via functions.php

Many features that can be added to WordPress with a few lines of code are not worth wrapping into a plugin. Instead of writing a plugin for short snippets, we tend to paste the code snippets into a theme file called functions.php.

PHP code snippet

JournalXtra’s new QuickSnips category is the place to be to grab simple WordPress code snippets.

Ideally, snippets should be placed into a child theme’s functions.php file to prevent them being overwritten when the parent (theme) is updated.

You can get a good explanation of what a child theme is by reading this page in the WordPress Codex.

To add code snippets to a WP website:

Use FTP or your web server’s file manager to browse to /wp-content/themes/THEME-NAME/functions.php

Copy and paste one or more snippets into the bottom of functions.php

Use the new feature as described under the snippets listing page

What to do when a site crashes after adding a snippet

Remove the added code from functions.php

Ask for advice in the snippet’s article comments board

What to do when the theme is changed

If you still need the feature added by a snippet, copy the code into your new theme’s child’s functions.php file.