Docs    Facebook    Customizations

Moving Custom JavaScript code out of our plugins

The Custom JavaScript field is deprecated. How to move your snippets to WPCode and keep them working.

Would you like to keep using your own JavaScript with your Facebook feed now that the Custom JS field is deprecated?

The Custom JS field in Facebook Feed is deprecated. The plugin no longer runs the code saved there. The same code works from WPCode, a separate plugin that adds your own code to the footer of your site.

This guide shows how to move your code there and how to add a new snippet.

Before you get started, make sure Facebook Feed is installed and activated on your WordPress site.

Moving Your Existing Snippet to WPCode

To get started, we will find the code you saved in the old Custom JS field and copy it.

  1. First, go to Facebook Feed » Settings in your WordPress dashboard and click the Feeds tab.
  2. Next, find the Custom JS box. It shows only when code was saved there before. The code appears in a read-only field below a message that the field has been deprecated. If the box isn’t there, you have no old code to move. In that case, skip to the next section.
  3. Then, review the code carefully and copy only your own lines. The plugin shows them inside its own wrapper. Its four opening lines run from <!-- Custom Facebook Feed JS --> to var $ = jQuery;. Its two closing lines are }cff_custom_js($); and </script>. You don’t need the wrapper. The template below replaces it.

Next, we will install WPCode.

  1. First, go to Plugins » Add Plugin in your WordPress dashboard.
  2. Next, search for WPCode. It is the free plugin on WordPress.org.
  3. Then, click Install Now. After the install finishes, click Activate. For more help, see How to Install a WordPress Plugin for a step-by-step guide.

Finally, we will add your code to the footer of your site.

  1. First, go to Code Snippets » Header and Footer in your WordPress dashboard.
  2. Next, paste the template from the snippet template section into the Footer box.
  3. Then, replace the comment line //Add your Custom JavaScript here with the lines you copied.
  4. Finally, save your changes.

Your code now runs from WPCode instead of from the plugin.

Adding a New Snippet

The same steps work for a brand new JavaScript snippet that you never saved in the plugin.

  1. First, install and activate WPCode as shown above.
  2. Next, go to Code Snippets » Header and Footer.
  3. Then, paste the template from the snippet template section into the Footer box and add your JavaScript where the comment says to.
  4. Finally, save your changes.

Your new snippet now runs from WPCode.

The Snippet Template

Your snippet needs this format, including the opening and closing script tags.

<!-- Custom Facebook Feed JS -->
<script type="text/javascript">
function cff_custom_js($){
  var $ = jQuery;
  //Add your Custom JavaScript here
}
cff_custom_js(jQuery);
</script>

The function is named cff_custom_js on purpose. In Facebook Feed Pro, the plugin runs a function with that name again each time the Load More button finishes loading more posts. Your code then also applies to the new posts.

The last line, cff_custom_js(jQuery);, runs the function once when the page loads. Older copies of this snippet ended with cff_custom_js($);. That line fails because WordPress doesn’t define a global $. If you have an older copy, change the last line to match the one above.

That’s it! Your custom JavaScript now runs from WPCode. For ready-made code recipes you can use in the same way, see our Facebook Feed custom snippets guide.

Frequently Asked Questions

Below, we’ve answered some of the most common questions about moving custom JavaScript out of Facebook Feed.

Will the code I saved in the old Custom JS field still run?

No. The plugin stopped running that code when the field was deprecated. It now only shows the code in a read-only box on the Feeds tab. Move it to WPCode to keep using it.

Do I have to keep the function name cff_custom_js?

Keep it if you want your code to run again after Load More in Facebook Feed Pro. If you don’t need that, any JavaScript in the Footer box runs when the page loads.

Where did the Custom CSS field go?

The plugin moved the CSS saved there into the WordPress Additional CSS field. To find it, go to Appearance » Customize » Additional CSS in your WordPress dashboard. Our Custom CSS guide covers it in more detail. You can also see How to Easily Add Custom CSS to Your WordPress Site for a general walkthrough.

support

Couldn’t find your answer in the docs?

Contact Support