&& is breaking the page in WordPress

后端 未结 2 1760
星月不相逢
星月不相逢 2020-12-21 17:01

I added this to my WordPress page

if (script.readyState && script.onload!==null){
    script.onreadystatechange= function () {
        if (this.ready         


        
2条回答
  •  庸人自扰
    2020-12-21 17:41

    Another option is to make a shortcode. In this example, the shortcode will only be printed if it contains the attributes x and y, e.g.: [myscript x="10" y="20"]. I'm using a simple script that shows a JS alert dialog with the attributes values.

    add_shortcode( 'myscript', 'sample_shortcode_so_6195635' );
    
    function sample_shortcode_so_6195635( $atts, $content = null )
    {   
        if( isset( $atts['x'] ) && isset( $atts['y'] ) )
        {
            $x = $atts['x'];
            $y = $atts['y'];
    
            // See: http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
            $html = <<Show Shortcode Atts
    
               
    HTML;
            return $html;
        }
    }
    

提交回复
热议问题