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.
javascript wordpress shortcode
add a comment |
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.
javascript wordpress shortcode
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
add a comment |
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.
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 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
add a comment |
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
add a comment |
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!
add a comment |
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!
add a comment |
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!
add a comment |
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!
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 at 21:34
answered Nov 21 at 21:27
Top-Bot
160112
160112
add a comment |
add a comment |
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 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