首页 > 解决方案 > functions.php 代码打印在屏幕 wordpress 上

问题描述

我正在尝试制作一个子主题,一切看起来都很好,直到我将 php 版本从 5.6 更改为 7.2.1,发生的情况是 functions.php 代码在屏幕上打印(回显),如果我检查图像没有意义。

这是我主页的最顶部

这是我的 functions.php,它只是 wordpress 中的一个示例,向您展示正在发生的事情:

<?function wporg_shortcode($atts = [], $content = null, $tag = '')
{
    // normalize attribute keys, lowercase
    $atts = array_change_key_case((array)$atts, CASE_LOWER);

    // override default attributes with user attributes
    $wporg_atts = shortcode_atts([
         "title" => "WordPress.org",
     ], $atts, $tag);

    // start output
    $o = '';

    // start box
    $o .= '<div class="wporg-box">';

    // title
    $o .= '<h2>' . esc_html__($wporg_atts['title'], 'wporg') . '</h2>';

    // enclosing tags
    if (!is_null($content)) {
        // secure output by executing the_content filter hook on $content
        $o .= apply_filters('the_content', $content);

        // run shortcode parser recursively
        $o .= do_shortcode($content);
    }

    // end box
    $o .= '</div>';

    // return output
    return $o;
}

function wporg_shortcodes_init()
{
    add_shortcode('wporg', 'wporg_shortcode');
}

add_action('init', 'wporg_shortcodes_init');

标签: phpwordpress

解决方案


开始文件<?php不是从<?


推荐阅读