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 provided by third party software with the “&”
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

How to add users to Google Analytics (GA4)?

Google Analytics: Is adding a user difficult for you? I'll explain how to add users…

2 weeks ago

How to Add Users to Google Search Console

Google Search Console is an essential tool for anyone who manages a website, allowing you to…

2 weeks ago

Search Engine positioning

https://youtu.be/XltdeciM1Pc Learn how to optimize your positioning on Google, Bing, YouTube, Amazon and social media…

2 weeks ago

SEO Consulting. What does a SEO consultant do?

Every business needs a strong online presence to attract potential customers . To achieve this, it is essential to…

3 weeks ago

Pinterest search optimization. Mastering Pinterest SEO

Pinterest, with over 450 million monthly Pinterest users, is not just a visual discovery engine,…

3 weeks ago

Ranking your site on Google in 2025: updated best practices guide

Updated guidelines on Google algorithm changes and how to stay competitive in search results. https://youtu.be/-DsqQg7cW1A…

4 weeks ago