Web design

How to replace “&amp%3B” in “&” from a script URL

A customer asked to implement a third-party service on his website under our site management (in this case it is Fidelo).

By inserting the scripts provided by this software, when you then publish the page and check with the console, the script appears changed with the addition of the parameter “&amp%3B” in place of the original “&” present in the provided script.

Script fornito dal software di terza parte con la "&"Script fornito dal software di terza parte con la "&"
Script provided by third party software with the “&”
Script risultante con parametro amp%3B risultante da console F12Script risultante con parametro amp%3B risultante da console F12
Resulting script with &amp%3B parameter resulting from F12 console

This small change does not allow the optimal execution of the script provided on the web page.

In this article we provide the solution we have implemented

What is the parameter &amp%3B?

The parameter “&amp%3B” often appears in URL links due to incorrect character encoding “&“. To remove it from a script, you need to decode the URL and remove the unwanted parameter.

How to remove it in Javasript?

Here are the steps to do it in JavaScript:

  1. Decode URL : Use decodeURIComponent()to transform the encoded URL into readable format.
  2. Remove unnecessary parameters : If you need to remove a specific parameter, you can manipulate the URL string.

Here is an example script:

// Let's assume this is the URL with the wrong parameter
let url = "https://example.com?param1=value1&amp%3Bparam2=value2";

// Decode URL
let decodedUrl = decodeURIComponent(url);

// Remove 'amp;' and replace it with the correct '&' symbol
let cleanedUrl = decodedUrl.replace("amp;", "&");

// Final output of the clean URL 
console.log(cleanedUrl);

This script:

  • Decodifica l’URL.
  • Rimuove amp3b, ripristinando il simbolo & nella posizione corretta.

How to remove &amp%3B in WordPress

To remove &amp%3B from a URL in WordPress, you can follow different paths depending on where the problem arises. Here are some common solutions:

1. PHP functions in the file functions.php

You can add a function in your theme’s functions.php file to remove or fix the parameter &amp%3B from URLs.

Here’s an example of code that decodes the URL and removes it &amp%3B before it’s displayed:

// Add this function to your theme's functions.php
function clean_amp_param($url) {
    // Decode the URL
    $decoded_url = urldecode($url);
    
    // Remove 'amp;' and replace it with '&'
    $cleaned_url = str_replace('amp;', '&', $decoded_url);
    
    return $cleaned_url;
}

// Apply the function to URLs generated by WordPress
add_filter('the_permalink', 'clean_amp_param');
add_filter('wp_get_attachment_url', 'clean_amp_param');
This function:
  • Decode the URL using urldecode().
  • Replace amp;with the correct symbol &.
  • Use the filter the_permalinkand wp_get_attachment_urlto apply it to URLs generated by WordPress.

2. Adding a plugin

If you don’t want to edit your theme files directly, you can use a plugin like “ Code Snippets ” to easily add PHP code without editing the functions.php.

  1. Install the “Code Snippets” plugin from WordPress.
  2. Create a new snippet with the above code.
  3. Save and activate the snippet.

If the error &amp%3B appears in links within your site content (like posts or pages), they may have been added manually or generated by shortcodes or plugins. You can do the following:

  • Search and Replace : Use a plugin like Better Search Replace to search the contents of the database &amp%3B and replace it with &.

4. Check AMP plugins

If you are using a plugin that handles AMP pages, check your plugin settings or update the plugin itself, as this could be the source of the problem.

5. Cache and CDN

Sometimes this type of error can be caused by caching or a CDN manipulating URLs. Make sure to clear your WordPress cache and if you use a CDN, check for problematic rewrite rules.

Sign up for the newsletter. Stay updated!

We will send you periodical important communications and news about the digital world. You can unsubscribe at any time by clicking the appropriate link at the bottom of the newsletter.

Dopstart

Dopstart è il sito di Paolino Donato ma anche il suo Nickname su Internet. Dopstart è un consulente SEO. Si occupa di posizionamento nei motori di ricerca fin dal 1998. Dal 2010 ha collaborato con Google in qualità di TC per Google News italiano e Google Noticias per i Paesi di Lingua spagnola e dal 2018 come Product Expert vedi curriculum

Share
Published by
Dopstart

Recent Posts

Instagram: new features for broadcast channels

Instagram introduces the option for creators to enable replies in broadcast channels, boosting engagement with…

2 weeks ago

Google Analytics integrates Customer Match to improve remarketing

A step towards more effective advertising campaigns thanks to the integration of first-party data. Customer…

2 weeks ago

Web banners: what are online advertisements?

What is a web banner and why is it important? A web banner is a…

3 weeks ago

Introduction to Web Design: guidelines

What is Web Design What is Web Design? It is the art of combining creativity,…

3 weeks ago

Elements and principles of design

What are the elements of design The fundamental elements of design (I call them "design…

3 weeks ago

Google explains why it’s hiding the results count in search

Why has Google hidden the results count? Google has recently chosen to make the results…

4 weeks ago