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.
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
&%3B
?
The parameter “
&%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:
- Decode URL : Use
decodeURIComponent()
to transform the encoded URL into readable format. - 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&%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
&%3B
from URLs.
Here’s an example of code that decodes the URL and removes it
&%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_permalink
andwp_get_attachment_url
to 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
.
- Install the “Code Snippets” plugin from WordPress.
- Create a new snippet with the above code.
- Save and activate the snippet.
3. Check the links in the contents
If the error
&%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
&%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.