How to forbid wordpress convert JS && to “&”

Add the following code in your theme’s file function.php such as ./wp-content/themes/hestia/functions.php.

function newautop($text)
{
    $newtext = "";
    $pos = 0;

    $tags = array('<!-- noformat on -->', '<!-- noformat off -->');
    $status = 0;

    while (!(($newpos = strpos($text, $tags[$status], $pos)) === FALSE))
    {
        $sub = substr($text, $pos, $newpos-$pos);

        if ($status)
            $newtext .= $sub;
        else
            $newtext .= convert_chars(wptexturize(wpautop($sub)));      //Apply both functions (faster)

        $pos = $newpos+strlen($tags[$status]);

        $status = $status?0:1;
    }

    $sub = substr($text, $pos, strlen($text)-$pos);

    if ($status)
        $newtext .= $sub;
    else
        $newtext .= convert_chars(wptexturize(wpautop($sub)));      //Apply both functions (faster)

    //To remove the tags
    $newtext = str_replace($tags[0], "", $newtext);
    $newtext = str_replace($tags[1], "", $newtext);

    return $newtext;
}

function newtexturize($text)
{
    return $text;   
}

function new_convert_chars($text)
{
    return $text;   
}

remove_filter('the_content', 'wpautop');
add_filter('the_content', 'newautop');

remove_filter('the_content', 'wptexturize');
add_filter('the_content', 'newtexturize');

remove_filter('the_content', 'convert_chars');
add_filter('the_content', 'new_convert_chars');

Then add <!-- noformat on --> and <!-- noformat off --> tags in your html code to forbid wordpress to convert our charater in the code snippet.

How to deep copy object in the javascript code

For example, I want to deep copy an array to avoid change the original elements. We can do it as this way,
let arrayCopy0 = JSON.parse(JSON.stringify(dataArray));

How to use sleep function in javascript code

There is no function sleep like language C in the javascript.
We can write a similar one like this.

    // parameter: msec
    function sleep(n){
        let b = true
        let timestamp = new Date().getTime()
        while(b){
            if(new Date().getTime() - timestamp > n){
                b = false
            }else{
                b = true;
            }
        }
    }
Categories: Web

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments

Content Summary
: Input your strings, the tool can get a brief summary of the content for you.

X
0
Would love your thoughts, please comment.x
()
x