Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
wordpress插件开发中的php语法_Php_Wordpress - Fatal编程技术网

wordpress插件开发中的php语法

wordpress插件开发中的php语法,php,wordpress,Php,Wordpress,我想用WordPress写一个插件,但是我收到一个语法错误(意外的结尾)。我想知道PHP的开头和结尾标记是否正确。代码如下: <?php /* Plugin Name: Chapter 2 - Page Header Output Plugin URI: Description: Adding output content to page header Version: 1.0 Author: Saeid Marouski Author URI: http://smarouski.com

我想用WordPress写一个插件,但是我收到一个语法错误(意外的结尾)。我想知道PHP的开头和结尾标记是否正确。代码如下:

<?php

/*
Plugin Name: Chapter 2 - Page Header Output
Plugin URI:
Description: Adding output content to page header
Version: 1.0
Author: Saeid Marouski
Author URI: http://smarouski.com
License: GPLv2
*/

add_action('wp_head','ch2pho_page_header_output');

function ch2pho_page_header_output() {
<script>
    (function(i,s,o,g,r,a,m) {i['GoogleAnalyticsObject']=r;
        i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();
            a=s.createElement(o),
            m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;
            m.parentNode.insertBefore(a,m)})(window,document,'script',
            'https://www.google-analytics.com/analytics.js','ga');

    ga('create','UA-0000000-0', 'auto');
    ga('send', 'pageview');
</script>
}
?>

您以错误的方式嵌入javascript代码

像这样试试看

<?php

/*
Plugin Name: Chapter 2 - Page Header Output
Plugin URI:
Description: Adding output content to page header
Version: 1.0
Author: Saeid Marouski
Author URI: http://smarouski.com
License: GPLv2
*/

add_action('wp_head','ch2pho_page_header_output');

function ch2pho_page_header_output() {

?>
<script>
(function(i,s,o,g,r,a,m) {i['GoogleAnalyticsObject']=r;
    i[r]=i[r]||function(){
        (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();
        a=s.createElement(o),
        m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;
        m.parentNode.insertBefore(a,m)})(window,document,'script',
    'https://www.google-analytics.com/analytics.js','ga');

ga('create','UA-0000000-0', 'auto');
ga('send', 'pageview');
</script>

<?php
  }
?>

(函数(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;
i[r]=i[r]| |函数(){
(i[r].q=i[r].q | |[]).push(参数)},i[r].l=1*新日期();
a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;
m、 parentNode.insertBefore(a,m)})(窗口、文档、“脚本”,
'https://www.google-analytics.com/analytics.js","ga",;
ga(“创建”、“UA-0000000-0”、“自动”);
ga(‘发送’、‘页面浏览’);

或者,您可以对
js
的每一行使用
echo
语句,语法错误是?您试图将HTML(您的
内容)混合到PHP中。可能重复