Peak Positions SEO Logo 231-922-9460

Adding JavaScript Snippets to an Individual WordPress Page

February 2nd, 2023

Does your WordPress website need to include custom JavaScript snippets for increased functionality or tracking? Including these lines of code via the WordPress block editor can be tricky for some users that may not be sure where the best location to include them is. Snippets of JavaScript such as Google events on conversion pages:

<!-- Event snippet for Example conversion page -->
    <script>
      gtag('event', 'conversion', {'send_to': 'AW-CONVERSION_ID/CONVERSION_LABEL',
        'value': 1.0,
        'currency': 'USD'
      });
    </script>

Or simple snippets to add new functionality to the page in which you may not want to use a plugin:

<script type="text/javascript"><!--
function showHide(elementid){
    if (document.getElementById(elementid).style.display == 'none'){
        document.getElementById(elementid).style.display = '';
    } else {
        document.getElementById(elementid).style.display = 'none';
    }
}
//-->
</script>

WordPress Custom HTML Block

WordPress Custom HTML Block Selection

The WordPress Custom HTML block is a block in the WordPress block editor (also known as Gutenberg) that allows you to insert and edit custom HTML code directly within your WordPress post or page. This block provides a way for users with coding knowledge to add and customize HTML elements, scripts, or embed code that may not be easily achievable through the standard block options.

WordPress Code Block

The WordPress Code block is a versatile tool in the WordPress block editor, offering users the ability to insert and customize code from various programming languages, including HTML, CSS, JavaScript, and more. This block provides a user-friendly code editor with syntax highlighting, making it easier for users to read and edit their code.

What is the difference between the Code Block and the Custom HTML Block?

The primary difference between the WordPress Custom HTML block and the Code block lies in their versatility and features. The Custom HTML block is specifically designed for adding HTML code, offering a straightforward interface without syntax highlighting and programming language selection. It’s ideal for users who primarily need to insert HTML code. On the other hand, the Code block is a more flexible option, accommodating various programming languages beyond HTML, such as CSS, JavaScript, and more.

Which Block should I use?

As outlined above we recommend using the Code Block for inserting JavaScript snippets as it is better equipped to handle this format and will not revert your code making it unusable on the front end in some scenarios. Some users will also use the Classic Editor block and edit it in code view which allows for the insertion of JavaScript as well. Although each block is usable with JavaScript the Code block is the best choice for most users. Contact our Digital Marketing Services company today for assistance with your custom code and tracking snippets.

TOP 20 SEO COMPANY WORLDWIDE SIX YEARS IN A ROW

Our SEO firm is comprised of a world class team of qualified coders, web designers, developers & SEO copywriters who strive to bring clients the highest quality SEO services in the industry.

Free Website Audit
Top 20 SEO Company Worldwide
  • Dell Logo
  • Ferris State University Logo
  • Sony Logo
  • Primerus Logo
  • Detroit Medical Center Logo
  • Tenet Health Logo
Contact Us

Peak Positions SEO
10850 East Traverse Highway, Suite 2290
Traverse City, MI 49684

231-922-9460

info@peakpositions.com