WordPress 5.1.1与multiple-content-blocks插件冲突致500错误的解决方法
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:
- Open the plugin file at
/wp-content/plugins/multiple-content-blocks/assets/inc/template-tags.php - 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; } - Update all calls to this function:
- Search through all files in the
multiple-content-blocksplugin folder for instances ofhas_block(and replace them withmcb_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 tomcb_has_block()as well
- Search through all files in the
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:
- Add a namespace declaration at the top of
template-tags.php:namespace MultipleContentBlocks; - Keep the function name as
has_block()but update internal calls to use the namespace:- Inside the plugin, replace
has_block(withMultipleContentBlocks\has_block( - In your theme/custom code, call the plugin function with its namespace:
<?php if( \MultipleContentBlocks\has_block('my-block') ) { ... } ?>
- Inside the plugin, replace
Important Notes
- Since
multiple-content-blocksis 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

