Square brackets getting changed to encoded character [WordPress]











up vote
0
down vote

favorite












Here is the problem, I have a JS code block that I would very much like to keep inline for speed reasons. This has not presented a problem in the past but for this specific function this is happening. I am using the PHP Output Buffer to render this through a shortcode.



Code that is rendered:



function get_price(arr, val) {
var price = Object.keys(arr).reduce((a, c) => {
var s = c.trim();
if (/d+-d+/.test(s)) {
var range = s.split("-");
if (+val >= parseInt(range[0]) && +val <= parseInt(range[1])) {
a = arr[c];
}
} else {
s = s.replace(/D/g, "");
if (+val >= +s) {
a = arr[c];
}
}
return a;
}, 0);
return price;
}


Code that is sent:



    function get_price(arr, val) {
var price = Object.keys(arr).reduce((a, c) => {
var s = c.trim();
if (/d+-d+/.test(s)) {
var range = s.split("-");
if (+val >= parseInt(range[0]) && +val <= parseInt(range[1])) {
a = arr[c];
}
} else {
s = s.replace(/D/g, "");
if (+val >= +s) {
a = arr[c];
}
}
return a;
}, 0);
return price;
}


I am at my wits end as too why this is happening so any help is appreciated!



I can also send more code if needed but don't want to overload my question with unnecessary code.










share|improve this question






















  • Can you try escaping the square brackets (with )?
    – zipkundan
    Nov 21 at 21:01










  • Why are only some of the brackets affected do you think?
    – Top-Bot
    Nov 21 at 21:05










  • I guess thats because you are trying render it through shortcode. Shortcode itself is rendered via square brackets. Though I am not very sure about the reason, its just the very first thought top of the mind.
    – zipkundan
    Nov 21 at 21:10










  • If that were the case then it should be changing all the square brackets but it is not
    – Top-Bot
    Nov 21 at 21:16















up vote
0
down vote

favorite












Here is the problem, I have a JS code block that I would very much like to keep inline for speed reasons. This has not presented a problem in the past but for this specific function this is happening. I am using the PHP Output Buffer to render this through a shortcode.



Code that is rendered:



function get_price(arr, val) {
var price = Object.keys(arr).reduce((a, c) => {
var s = c.trim();
if (/d+-d+/.test(s)) {
var range = s.split("-");
if (+val >= parseInt(range[0]) && +val <= parseInt(range[1])) {
a = arr[c];
}
} else {
s = s.replace(/D/g, "");
if (+val >= +s) {
a = arr[c];
}
}
return a;
}, 0);
return price;
}


Code that is sent:



    function get_price(arr, val) {
var price = Object.keys(arr).reduce((a, c) => {
var s = c.trim();
if (/d+-d+/.test(s)) {
var range = s.split("-");
if (+val >= parseInt(range[0]) && +val <= parseInt(range[1])) {
a = arr[c];
}
} else {
s = s.replace(/D/g, "");
if (+val >= +s) {
a = arr[c];
}
}
return a;
}, 0);
return price;
}


I am at my wits end as too why this is happening so any help is appreciated!



I can also send more code if needed but don't want to overload my question with unnecessary code.










share|improve this question






















  • Can you try escaping the square brackets (with )?
    – zipkundan
    Nov 21 at 21:01










  • Why are only some of the brackets affected do you think?
    – Top-Bot
    Nov 21 at 21:05










  • I guess thats because you are trying render it through shortcode. Shortcode itself is rendered via square brackets. Though I am not very sure about the reason, its just the very first thought top of the mind.
    – zipkundan
    Nov 21 at 21:10










  • If that were the case then it should be changing all the square brackets but it is not
    – Top-Bot
    Nov 21 at 21:16













up vote
0
down vote

favorite









up vote
0
down vote

favorite











Here is the problem, I have a JS code block that I would very much like to keep inline for speed reasons. This has not presented a problem in the past but for this specific function this is happening. I am using the PHP Output Buffer to render this through a shortcode.



Code that is rendered:



function get_price(arr, val) {
var price = Object.keys(arr).reduce((a, c) => {
var s = c.trim();
if (/d+-d+/.test(s)) {
var range = s.split("-");
if (+val >= parseInt(range[0]) && +val <= parseInt(range[1])) {
a = arr[c];
}
} else {
s = s.replace(/D/g, "");
if (+val >= +s) {
a = arr[c];
}
}
return a;
}, 0);
return price;
}


Code that is sent:



    function get_price(arr, val) {
var price = Object.keys(arr).reduce((a, c) => {
var s = c.trim();
if (/d+-d+/.test(s)) {
var range = s.split("-");
if (+val >= parseInt(range[0]) && +val <= parseInt(range[1])) {
a = arr[c];
}
} else {
s = s.replace(/D/g, "");
if (+val >= +s) {
a = arr[c];
}
}
return a;
}, 0);
return price;
}


I am at my wits end as too why this is happening so any help is appreciated!



I can also send more code if needed but don't want to overload my question with unnecessary code.










share|improve this question













Here is the problem, I have a JS code block that I would very much like to keep inline for speed reasons. This has not presented a problem in the past but for this specific function this is happening. I am using the PHP Output Buffer to render this through a shortcode.



Code that is rendered:



function get_price(arr, val) {
var price = Object.keys(arr).reduce((a, c) => {
var s = c.trim();
if (/d+-d+/.test(s)) {
var range = s.split("-");
if (+val >= parseInt(range[0]) && +val <= parseInt(range[1])) {
a = arr[c];
}
} else {
s = s.replace(/D/g, "");
if (+val >= +s) {
a = arr[c];
}
}
return a;
}, 0);
return price;
}


Code that is sent:



    function get_price(arr, val) {
var price = Object.keys(arr).reduce((a, c) => {
var s = c.trim();
if (/d+-d+/.test(s)) {
var range = s.split("-");
if (+val >= parseInt(range[0]) && +val <= parseInt(range[1])) {
a = arr[c];
}
} else {
s = s.replace(/D/g, "");
if (+val >= +s) {
a = arr[c];
}
}
return a;
}, 0);
return price;
}


I am at my wits end as too why this is happening so any help is appreciated!



I can also send more code if needed but don't want to overload my question with unnecessary code.







javascript wordpress shortcode






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 at 20:57









Top-Bot

160112




160112












  • Can you try escaping the square brackets (with )?
    – zipkundan
    Nov 21 at 21:01










  • Why are only some of the brackets affected do you think?
    – Top-Bot
    Nov 21 at 21:05










  • I guess thats because you are trying render it through shortcode. Shortcode itself is rendered via square brackets. Though I am not very sure about the reason, its just the very first thought top of the mind.
    – zipkundan
    Nov 21 at 21:10










  • If that were the case then it should be changing all the square brackets but it is not
    – Top-Bot
    Nov 21 at 21:16


















  • Can you try escaping the square brackets (with )?
    – zipkundan
    Nov 21 at 21:01










  • Why are only some of the brackets affected do you think?
    – Top-Bot
    Nov 21 at 21:05










  • I guess thats because you are trying render it through shortcode. Shortcode itself is rendered via square brackets. Though I am not very sure about the reason, its just the very first thought top of the mind.
    – zipkundan
    Nov 21 at 21:10










  • If that were the case then it should be changing all the square brackets but it is not
    – Top-Bot
    Nov 21 at 21:16
















Can you try escaping the square brackets (with )?
– zipkundan
Nov 21 at 21:01




Can you try escaping the square brackets (with )?
– zipkundan
Nov 21 at 21:01












Why are only some of the brackets affected do you think?
– Top-Bot
Nov 21 at 21:05




Why are only some of the brackets affected do you think?
– Top-Bot
Nov 21 at 21:05












I guess thats because you are trying render it through shortcode. Shortcode itself is rendered via square brackets. Though I am not very sure about the reason, its just the very first thought top of the mind.
– zipkundan
Nov 21 at 21:10




I guess thats because you are trying render it through shortcode. Shortcode itself is rendered via square brackets. Though I am not very sure about the reason, its just the very first thought top of the mind.
– zipkundan
Nov 21 at 21:10












If that were the case then it should be changing all the square brackets but it is not
– Top-Bot
Nov 21 at 21:16




If that were the case then it should be changing all the square brackets but it is not
– Top-Bot
Nov 21 at 21:16












1 Answer
1






active

oldest

votes

















up vote
0
down vote













So... Not sure why this worked but I converted the 2 offending areas into JS vars and then the code was no longer getting encoded.



 function get_price(arr, val) {
var price = Object.keys(arr).reduce((a, c) => {
var s = c.trim();
if (/d+-d+/.test(s)) {
var range = s.split("-");
var t1 = parseInt(range[1]); // new added var
var t2 = arr[c]; // new added var
if (+val >= parseInt(range[0]) && +val <= t1) { // replaced code with t1 here
a = t2; // replaced code with t2 here
}
} else {
s = s.replace(/D/g, "");
if (+val >= +s) {
a = arr[c];
}
}
return a;
}, 0);
return price;
}


If anyone know why and wants to help the universe by sharing their knowledge then go right ahead. If not then hopefully this helps someone!






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53420376%2fsquare-brackets-getting-changed-to-encoded-character-wordpress%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    So... Not sure why this worked but I converted the 2 offending areas into JS vars and then the code was no longer getting encoded.



     function get_price(arr, val) {
    var price = Object.keys(arr).reduce((a, c) => {
    var s = c.trim();
    if (/d+-d+/.test(s)) {
    var range = s.split("-");
    var t1 = parseInt(range[1]); // new added var
    var t2 = arr[c]; // new added var
    if (+val >= parseInt(range[0]) && +val <= t1) { // replaced code with t1 here
    a = t2; // replaced code with t2 here
    }
    } else {
    s = s.replace(/D/g, "");
    if (+val >= +s) {
    a = arr[c];
    }
    }
    return a;
    }, 0);
    return price;
    }


    If anyone know why and wants to help the universe by sharing their knowledge then go right ahead. If not then hopefully this helps someone!






    share|improve this answer



























      up vote
      0
      down vote













      So... Not sure why this worked but I converted the 2 offending areas into JS vars and then the code was no longer getting encoded.



       function get_price(arr, val) {
      var price = Object.keys(arr).reduce((a, c) => {
      var s = c.trim();
      if (/d+-d+/.test(s)) {
      var range = s.split("-");
      var t1 = parseInt(range[1]); // new added var
      var t2 = arr[c]; // new added var
      if (+val >= parseInt(range[0]) && +val <= t1) { // replaced code with t1 here
      a = t2; // replaced code with t2 here
      }
      } else {
      s = s.replace(/D/g, "");
      if (+val >= +s) {
      a = arr[c];
      }
      }
      return a;
      }, 0);
      return price;
      }


      If anyone know why and wants to help the universe by sharing their knowledge then go right ahead. If not then hopefully this helps someone!






      share|improve this answer

























        up vote
        0
        down vote










        up vote
        0
        down vote









        So... Not sure why this worked but I converted the 2 offending areas into JS vars and then the code was no longer getting encoded.



         function get_price(arr, val) {
        var price = Object.keys(arr).reduce((a, c) => {
        var s = c.trim();
        if (/d+-d+/.test(s)) {
        var range = s.split("-");
        var t1 = parseInt(range[1]); // new added var
        var t2 = arr[c]; // new added var
        if (+val >= parseInt(range[0]) && +val <= t1) { // replaced code with t1 here
        a = t2; // replaced code with t2 here
        }
        } else {
        s = s.replace(/D/g, "");
        if (+val >= +s) {
        a = arr[c];
        }
        }
        return a;
        }, 0);
        return price;
        }


        If anyone know why and wants to help the universe by sharing their knowledge then go right ahead. If not then hopefully this helps someone!






        share|improve this answer














        So... Not sure why this worked but I converted the 2 offending areas into JS vars and then the code was no longer getting encoded.



         function get_price(arr, val) {
        var price = Object.keys(arr).reduce((a, c) => {
        var s = c.trim();
        if (/d+-d+/.test(s)) {
        var range = s.split("-");
        var t1 = parseInt(range[1]); // new added var
        var t2 = arr[c]; // new added var
        if (+val >= parseInt(range[0]) && +val <= t1) { // replaced code with t1 here
        a = t2; // replaced code with t2 here
        }
        } else {
        s = s.replace(/D/g, "");
        if (+val >= +s) {
        a = arr[c];
        }
        }
        return a;
        }, 0);
        return price;
        }


        If anyone know why and wants to help the universe by sharing their knowledge then go right ahead. If not then hopefully this helps someone!







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 21 at 21:34

























        answered Nov 21 at 21:27









        Top-Bot

        160112




        160112






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53420376%2fsquare-brackets-getting-changed-to-encoded-character-wordpress%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Trompette piccolo

            How do I get these specific pathlines to nodes?

            What visual should I use to simply compare current year value vs last year in Power BI desktop