首页 > 解决方案 > WP 5 中的简码被破坏?

问题描述

我正在与一个客户合作,该客户需要其主要品牌旗下的多个网站。我们使用 wpengine 来暂存它们,它们都使用相同的基本 css、模板等。

问题是,我开发的前几个站点安装了 WP 4.9.x,它们都已升级到 4.9.9。没有汗水,一切正常。虽然我已经开始在 WP v5 上展示其他人,但突然之间事情就发生了变化。我已经停用了插件等,试图找到一个没有运气的罪魁祸首。

我最头疼的是短代码。我使用 WP codex 方法在 functions.php 中编写了相当多的自定义简码,甚至使用 EXACT SAME functions.php 文件,以及为经典编辑器禁用 Gutenberg,我的简码仍然在 <p> 块中显示为普通文本。我什至尝试使用“echo do_shortcode('[custom-shortcode]');”通过模板文件传递简码 输出仍然是纯文本。

    //from functions.php
    function ihButtonPurp($atts, $content = null) {
    $burl = (shortcode_atts(array(
        "to" => "#"
    ), $atts));
    return '<div class="ih-button"><a href="'.$burl["to"].'"><p>'.$content.'</p></a></div>'; }

    add_shortcode("buttonP", "ihButtonPurp");

    // from template.php
    <?php the_content(); ?>
    <?php echo do_shortcode('[buttonP to="#"]Some Link[/buttonP]'); ?>

    //both uses result in plain text output

这个完全相同的 php 和简码仍然适用于我的 WP 4.9.9 网站。为什么这不适用于 WP 5?

标签: wordpressshortcodewordpress-gutenbergwordpress-shortcode

解决方案


推荐阅读