Question

I want to change the meta robots tag value from index,follow to noindex,nofollow to all category filter pages only. How can I achieve this?

I am trying to do this by jquery below-

<script type="text/javascript">
     var getCurrentUrl = window.location.href;
    if(getCurrentUrl.includes("?")){
    document.getElementsByTagName('meta')["robots"].content="INDEX,NOFOLLOW" ;

    }

</script>

But it's not updating the value of current meta robots tag.

No correct solution

OTHER TIPS

There is one more way you can try like check if the current route is category and if the parameters is set or not and based on those condition you can change the meta tags, or, if you prefer using an JS then try the following code.

function urlParam(name){
    var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
    return results[1] || 0;
}
document.observe("dom:loaded", function() {
    if(urlParam('cat')) {
        //process your code
    }
});
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top