1. Home
  2. Knowledge Base
  3. Document Library Pro
  4. Advanced Usage

How to add custom code snippets to your website

Sometimes you may wish to add a custom code snippet to your website, for example in order to customize one of our plugins. This article provides several easy ways to do this.

If you are not a developer then you should be very careful when adding custom code snippets. If you're not sure what you're doing then we recommend asking your developer or posting a job on Codeable to find someone who can do it for you.

functions.php file

You can add the code snippet to the functions.php file of your child theme (if you are using an off-the-shelf theme then never edit files directly in the parent theme). In order to do this, go to Appearance → Theme File Editor and then edit the functions.php file for your active theme. You can paste the code snippet at the end of the file and then save it.

Add code snippet Customizer

If you are using a child theme then it is important to add the code to the functions.php file in the child theme. This is because if you add it to the parent theme then your changes may be lost when you update the theme in future.

Depending on the permissions on your website and your theme, the above option may not be available to you. If you can't use this method then you can use a code snippets plugin instead.

Use a code snippets plugin

The free Code Snippets or WPCode - Insert Headers and Footers + Custom Code Snippets plugins makes it easy to add custom code to your site. The following instructions assume you're using Code Snippets:

  1. Go to Plugins → Add New and search for "Code Snippets".
  2. Install and activate the plugin.
  3. Go to the 'Snippets' section which appears in the left hand side of the admin.
  4. Follow the on-screen instructions to add a new snippet, which involves entering both the title and the code.
  5. If you’re not sure whether your code snippet is for the admin area or front end then select the first option: "Run snippet everywhere".
Code Snippets plugin

Related Articles

If searching the knowledge base hasn't answered your question, please contact support.