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 finding the filter you need from this knowledge base. 

To install the plugin, follow these instructions.

  1. Once installed and activated, go to Snippets in your dashboard menu.
  2. Click on Add New.
  3. Add a Title, which could be the title of this article.
  4. Paste the code you copied in step 1 to the Code section.
  5. Add a Description or Tags if you wish to do so. It is not required.
  6. Click on Save Changes and Activate to save the filter and activate it.
    1. Or click on Save Changes to save the filter and activate it later.
  7. Your action or filter is now stored and active on your site.
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 article 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