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
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:

  1. Use FTP or your web server’s file manager to browse to /wp-content/themes/THEME-NAME/functions.php
  2. Copy and paste one or more snippets into the bottom of functions.php
  3. Use the new feature as described under the snippets listing page

What to do when a site crashes after adding a snippet

  1. Remove the added code from functions.php
  2. Ask for advice in the snippet’s article comments board

What to do when the theme is changed

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

Need more advice? Ask questions in the comments board below.

Sharing is caring!

Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Newest Most Voted
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x