How to Add Actions and Filters

When using WP RSS Aggregator, or any other plugin for that matter, there are times when you will need to add a custom action or filter to your site for added functionality, or even to remove some.

While WordPress itself suggests using your theme’s functions.php file for this, we recommend using a child theme or a third-party plugin that allow you to do this without modifying the parent theme files.

Here are a few reasons why this is recommended:

  1. The moment you upgrade your parent theme, the functions.php file is overwritten. So, whatever you added is suddenly gone, and you have to add it again from scratch on every theme update.
  2. If you change your theme, you will need to add the same code to the new theme again.

If you are using a child theme, there is still the possibility of making a mistake in your PHP code, which could break the site and require FTP access to fix it. For this reason, we believe Method 1 below is the safest option.

Method 1: Code Snippets Plugin (Recommended)

To use this method, we recommend downloading the filter you need from this documentation website. Each filter has a .json file available that can be used to import the exact filter we provide into your site.

To install the plugin,  follow these instructions.

  1. Once installed and activated, go to Snippets in your dashboard menu.
  2. Click on Import.
  3. Click on the Choose files button.
  4. Select the .json file you downloaded from our documentation.
  5. Click on the Upload files and import button.
  6. Go to Snippets > All Snippets.
  7. Find the snippet you just uploaded and click Activate beneath it.
  8. Your action or filter is now stored and active on your site.

If you wish to add the code snippet yourself without using the .json file provided by us, you may do so. Rather than choosing the Import option, you can choose to Add New and copy the code into the area titled Code, save the changes, and activate at will.

IMPORTANT: Be careful not to have duplicate filters activated at the same time through the Code Snippets plugin. In some cases, this may cause a fatal error to occur. If that does happen, please  refer to this page to recover your website.

Method 2: Use Your Child Theme’s functions.php File

The best way to do this is to use FTP access. This ensures that you can easily fix any mistakes easily and quickly, should you make any. If you do not know what FTP access is, please do not attempt to use this method.

  1. Access your site via FTP.
  2. Download your child theme’s functions.php file.
  3. Keep a copy of the original file somewhere on your desktop.
  4. Open it in a code editor such as Sublime Text.
  5. Copy the code from our documentation to the bottom of the file.
    1. If the code snippet you are copying includes an opening PHP tag (<?php), do not copy it.
    2. If there is a closing PHP tag (?>) at the bottom of your functions.php file, the code must be pasted above it.
  6. Save the file.
  7. Re-upload it to your site via the FTP client, replacing the original file.

Your action or filter is now saved and live on your site. If the code has a mistake and it broke your site, repeat step 7, this time uploading the original file and replacing the modified one.

Still need help? Contact Us Contact Us