Square brackets getting changed to encoded character [WordPress]
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
add a comment |
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
Can you try escaping the square brackets (with )?
– zipkundan
Nov 21 '18 at 21:01
Why are only some of the brackets affected do you think?
– Top-Bot
Nov 21 '18 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 '18 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 '18 at 21:16
add a comment |
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
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
javascript wordpress shortcode
asked Nov 21 '18 at 20:57
Top-BotTop-Bot
175113
175113
Can you try escaping the square brackets (with )?
– zipkundan
Nov 21 '18 at 21:01
Why are only some of the brackets affected do you think?
– Top-Bot
Nov 21 '18 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 '18 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 '18 at 21:16
add a comment |
Can you try escaping the square brackets (with )?
– zipkundan
Nov 21 '18 at 21:01
Why are only some of the brackets affected do you think?
– Top-Bot
Nov 21 '18 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 '18 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 '18 at 21:16
Can you try escaping the square brackets (with )?
– zipkundan
Nov 21 '18 at 21:01
Can you try escaping the square brackets (with )?
– zipkundan
Nov 21 '18 at 21:01
Why are only some of the brackets affected do you think?
– Top-Bot
Nov 21 '18 at 21:05
Why are only some of the brackets affected do you think?
– Top-Bot
Nov 21 '18 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 '18 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 '18 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 '18 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 '18 at 21:16
add a comment |
1 Answer
1
active
oldest
votes
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!
add a comment |
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',
autoActivateHeartbeat: false,
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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!
add a comment |
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!
add a comment |
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!
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!
edited Nov 21 '18 at 21:34
answered Nov 21 '18 at 21:27
Top-BotTop-Bot
175113
175113
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Can you try escaping the square brackets (with )?
– zipkundan
Nov 21 '18 at 21:01
Why are only some of the brackets affected do you think?
– Top-Bot
Nov 21 '18 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 '18 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 '18 at 21:16