WordPress自定義主題出現致命錯誤怎麼辦?添加代碼解決

在本地電腦測試更換新WordPress主題,嘗試自定義主題時,出現以下致命錯誤 ▼

WordPress自定義主題出現致命錯誤怎麼辦?添加代碼解決

WordPress自定義主題出現致命錯誤怎麼辦?

如果在打開WordPress自定義主題和背景菜單時,會遇到類似以下的致命錯誤:

Fatal error: Uncaught exception 'Exception' with message 'Supplied nav_menu_item value missing property: description' in D:\xampp\htdocs\wp\ceshimuban\wp-includes\customize\class-wp-customize-nav-menu-item-setting.php:183 Stack trace: #0 D:\xampp\htdocs\wp\ceshimuban\wp-includes\class-wp-customize-nav-menus.php(820): WP_Customize_Nav_Menu_Item_Setting->__construct(Object(WP_Customize_Manager), 'nav_menu_item[1...', Array) #1 [internal function]: WP_Customize_Nav_Menus->customize_register(Object(WP_Customize_Manager)) #2 D:\xampp\htdocs\wp\ceshimuban\wp-includes\class-wp-hook.php(303): call_user_func_array(Array, Array) #3 D:\xampp\htdocs\wp\ceshimuban\wp-includes\class-wp-hook.php(327): WP_Hook->apply_filters('', Array) #4 D:\xampp\htdocs\wp\ceshimuban\wp-includes\plugin.php(470): WP_Hook->do_action(Array) #5 D:\xampp\htdocs\wp\ceshimuban\wp-includes\class-wp-customize-manager.php(933): do_action('customize_regis...', Object(WP_Customize_Manager)) #6 [internal function]: WP_Customize_Manager->wp_loaded('') #7 D:\xampp\htd in D:\xampp\htdocs\wp\ceshimuban\wp-includes\customize\class-wp-customize-nav-menu-item-setting.php on line 183
There has been a critical error on this website. Please check your site admin email inbox for instructions.

Learn more about troubleshooting WordPress.

如何解決Supplied nav_menu_item value missing property: description'?

我們可以在WordPress主題的function.php文件中,添加以下代碼修復它:

/**
* 解决WordPress自定义主题时出现致命错误 By 陈沩亮博客
* https://www.chenweiliang.com/cwl-19302.html
**/
add_filter('wp_get_nav_menu_items', 'my_wp_get_nav_menu_items', 10, 3);
function my_wp_get_nav_menu_items($items, $menu, $args) {
foreach($items as $key => $item)
$items[$key]->description = '';

return $items;
}

陳溈亮經過測試,WordPress主題的function.php文件中,添加以上代碼後,是可以解決WordPress Fatal error: Uncaught exception 'Exception' with message 'Supplied nav_menu_item value missing property: description'的問題。

希望陳溈亮博客( https://www.chenweiliang.com/ ) 分享的《WordPress自定義主題出現致命錯誤怎麼辦?添加代碼解決》,對您有幫助。

歡迎分享本文鏈接:https://www.chenweiliang.com/cwl-19302.html

歡迎加入陳溈亮博客的Telegram 頻道,獲取最新更新!

🔔 率先在頻道置頂目錄獲取寶貴的《ChatGPT 內容行銷AI 工具使用指南》! 🌟
📚 這份指南蘊含價值巨大,🌟難逢的機遇,切勿錯失良機! ⏰⌛💨
喜歡就分享和按贊!
您的分享和按贊,是我們持續的動力!

 

發表評論

您的電子郵箱地址不會被公開。 必填項已用 * 標註

滾動到頂部