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:
- Install Insert HTML Snippet WordPress Plugin from https://wordpress.org/plugins/insert-html-snippet/
- Activate it
- Create a snippet
- Add the shortcode on an existing or a new page/post
- Temporarily switch to Text mode
- Paste the code
- Switch back to Visual mode
- Save Draft or Publish
- View the page
- Inspect the source code
Here's a 40 second animated gif that shows how to insert an HTML snippet
Here's a 3min video how to do it (with voice over)