搜尋

首頁  >  問答  >  主體

在WordPress 6.3.0中,已棄用函式WP_Scripts::print_inline_script

<p>我目前正在開發一個WordPress網站,在運行我的程式碼時遇到以下錯誤訊息:</p> <p><code>HP Deprecated: Function WP_Scripts::print_inline_script is <strong>deprecated</strong> since version 6.3.0! Use WP_Scripts::get_inline_script_data() or WP_Script_clid in VWP_script_data( :laragon-8laragonwwwdev-myprojectswp-includesfunctions.php on line 5453</code></p> <p>我不確定該如何處理這個棄用警告。我嘗試在WordPress文件中尋找信息,但仍然感到困惑。請有人指導我如何解決這個問題嗎? </p> <ul> <li>我已經在WordPress文件中搜尋了這個錯誤。 </li> <li>我嘗試透過搜尋引擎尋找解決方案,但沒有找到合適的答案。 </li> </ul><p><br /></p>
P粉754477325P粉754477325575 天前693

全部回覆(1)我來回復

  • P粉562845941

    P粉5628459412023-08-17 13:56:35

    函數WP_Scripts::print_inline_script從WordPress 6.3.0版本開始已被棄用。為了解決這個問題,您應該更新您的程式碼,使用WP_Scripts::get_inline_script_data()或WP_Scripts::get_inline_script_tag()。建議使用這些替代方法以確保與較新版本的WordPress相容。

    例如,如果您的程式碼如下所示:

    WP_Scripts::print_inline_script($handle, $position);

    您應該將其替換為:

    使用get_inline_script_data():

    $script_data = WP_Scripts::get_data($handle, 'data');
    echo $script_data;

    使用get_inline_script_tag():

    $script_data = WP_Scripts::get_data($handle, 'data');
    echo WP_Scripts::get_script_tag($handle, $script_data);

    這將幫助您避免使用已棄用的函數,並保持與WordPress核心更新的兼容性。

    回覆
    0
  • 取消回覆