skip to Main Content

Elementor Pro has a new widget, video playlist. It appends a parameter to the URL, like so: http://aaronpenton.net/ampcreative/vip/about-vip/?playlist=f68425e&video=b8a9967

This is obviously terrible for SEO and UX. Is there a way to remove the ?playlist=f68425e&video=b8a9967 ?

2

Answers


  1. This should do the trick.

    const url = 'http://aaronpenton.net/ampcreative/vip/about-vip/?playlist=f68425e&video=b8a9967'
    url.replace(url.split('/')[6], '')
    
    1. split, well.. splits the string into an array by the /
      character.

    2. At index 6 the array contains the ?playlist=f68425e&video=b8a9967 substring which can than be removed (i.e. replaced by the empty string) using replace.

    A more general approach to removing the last part of the url might
    be to use the array length instead of specifying the index:

    const url = 'http://aaronpenton.net/ampcreative/vip/about-vip/?playlist=f68425e&video=b8a9967'
    const urlArr = url.split('/')
    url.replace(urlArr[urlArr.length - 1], '')
    

    Update:

    Another way to do this is using the URL API

    const url = new URL('http://aaronpenton.net/ampcreative/vip/about-vip/?playlist=f68425e&video=b8a9967');
    const result = url.origin + url.pathname
    

    or in a function:

    const removeParameter = u => {
      const url = new URL(u);
      return url.origin + url.pathname
    }
    

    You might have to check the specification for further details (browser support etc)

    Login or Signup to reply.
  2. My brother help me with the next script.
    Put a "HTML Elementor Widget" with the following:

        <script>
    function getURLParameter(name) {
      return decodeURI((RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]);
    }
    
    function hideURLParams() {
      //Parameters to hide (ie ?playlist=value, ?video=value, etc)
      var hide = ['playlist','video'];
      for(var h in hide) {
        if(getURLParameter(h)) {
          history.replaceState(null, document.getElementsByTagName("title")[0].innerHTML, window.location.pathname);
        }
      }
    }
    
    window.onload = hideURLParams;
    </script>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search