Inserting HTML code is sometimes needed because you may want to insert a tracking code on a specific page or use custom CSS for a given page/post. Another usage for this kind of plugin is to paste a code (using HTML comment) that is going to be used for site verification purposes. Of course there are many ways to do anything.

This post focuses on how to insert an HTML snippet using Insert HTML Snippet WordPress Plugin.

If you need the code to be shown on all pages or posts such for example Google Analytics or Facebook pixel code then you'll either have to use another plugin for that or update your footer.php of your (child) theme to include the code snippet.

The reason for using a plugin for including snippets is because WordPress' rich text editor may strip out some of the code either during the initial editing or after saving the content. The code has to be displayed as is in order to work properly.

Keep in mind that when copying the snippet shortcode the browser will also copy some additional HTML code. You don't want that additional code displayed as part of your code so you need to switch to Text mode temporarily, then paste the code and then switch back to Visual mode.

The steps are the following:

  1. Install Insert HTML Snippet WordPress Plugin from https://wordpress.org/plugins/insert-html-snippet/
  2. Activate it
  3. Create a snippet
  4. Add the shortcode on an existing or a new page/post
    1. Temporarily switch to Text mode
    2. Paste the code
    3. Switch back to Visual mode
  5. Save Draft or Publish
  6. View the page
  7. Inspect the source code

Here's a 40 second animated gif that shows how to insert an HTML snippet

How to Insert Code Snippets into WordPress using Insert HTML Snippet WordPress Plugin

 

Here's a 3min video how to do it (with voice over)