You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WordPress 5.1.1与multiple-content-blocks插件冲突致500错误的解决方法

Fixing "Cannot redeclare has_block()" Error After WordPress 5.1.1 Upgrade

This error pops up because WordPress 5.0+ introduced a core has_block() function, but your unmaintained multiple-content-blocks plugin declares its own function with the exact same name—PHP won’t allow duplicate function names, which triggers the fatal 500 server error. Here are three actionable solutions, ordered by simplicity and reliability:

1. Rename the Plugin's has_block() Function (Most Reliable)

This is the cleanest fix since it eliminates the name conflict entirely. Follow these steps:

  1. Open the plugin file at /wp-content/plugins/multiple-content-blocks/assets/inc/template-tags.php
  2. Go to line 67 and rename the function to something unique (e.g., mcb_has_block()):
    /**
     * Check if the block has content
     *
     * @param string $name
     * @param array $args Optional. Additional arguments, see get_the_block for more information
     */
    function mcb_has_block( $name, $args = array() ) {
        if( 0 < strlen( get_the_block( $name, $args ) ) ) return true;
        return false;
    }
    
  3. Update all calls to this function:
    • Search through all files in the multiple-content-blocks plugin folder for instances of has_block( and replace them with mcb_has_block(
    • If your theme or custom code uses the plugin's has_block() function (e.g., <?php if(has_block('header-block')) { ... } ?>), update those to mcb_has_block() as well

2. Add a Function Existence Check (Temporary Quick Fix)

If you need a stopgap solution without changing function names, wrap the plugin's function in a check to only declare it if the core function doesn’t exist. Note: This will break plugin functionality if your code relies on the plugin's has_block() behavior, since the core function will be used instead.

Modify the plugin's function like this:

/**
 * Check if the block has content
 *
 * @param string $name
 * @param array $args Optional. Additional arguments, see get_the_block for more information
 */
if ( ! function_exists( 'has_block' ) ) {
    function has_block( $name, $args = array() ) {
        if( 0 < strlen( get_the_block( $name, $args ) ) ) return true;
        return false;
    }
}

3. Use Namespaces (More Advanced)

For a more scalable fix, wrap the plugin's function in a unique namespace to isolate it from core functions:

  1. Add a namespace declaration at the top of template-tags.php:
    namespace MultipleContentBlocks;
    
  2. Keep the function name as has_block() but update internal calls to use the namespace:
    • Inside the plugin, replace has_block( with MultipleContentBlocks\has_block(
    • In your theme/custom code, call the plugin function with its namespace: <?php if( \MultipleContentBlocks\has_block('my-block') ) { ... } ?>

Important Notes

  • Since multiple-content-blocks is unmaintained, make a backup of the modified plugin files to avoid losing changes if the plugin ever gets updated (unlikely, but safe to do)
  • Consider replacing the plugin with a maintained alternative long-term to avoid future compatibility issues

内容的提问来源于stack exchange,提问作者BCole

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 04:44:01