• Home
  • Blog
  • 如何在 WordPress 中添加動態插件就緒側邊欄

如何在 WordPress 中添加動態插件就緒側邊欄

0 comments

如何在 WordPress 中添加動態插件就緒側邊欄

插件是如此重要的一部分,以至於很難想像一個沒有插件的 WordPress 主題。插件是可以拖放到側邊欄或主題中的任何其他插件就緒區域的可執行腳本。許多讀者利用插件來向其側邊欄添加自定義元素。然而,這篇文章是為那些想學習如何在 WordPress 主題中添加動態插件就緒側邊欄或插件就緒區域的好奇用戶準備的。

在 WordPress 中註冊側邊欄或插件就緒區域

首先你需要為你的主題註冊側邊欄或插件就緒區域。你可以註冊多個側邊欄和插件就緒區域。將以下代碼複製並粘貼到您的主題 functions.php 文件中:

function wpb_widgets_init() {

	register_sidebar( array(
		'name' => __( '主側邊欄', 'wpb' ),
		'id' => 'sidebar-1',
		'description' => __( '主側邊欄顯示在每頁的右側,首頁模板除外', 'wpb' ),
		'before_widget' => '',
		'before_title' => '

', 'after_title' => '

', ) ); register_sidebar( array( 'name' =>__( '首頁側邊欄', 'wpb'), 'id' => 'sidebar-2', 'description' => __( '顯示在靜態首頁模板上', 'wpb' ), 'before_widget' => '', 'before_title' => '

', 'after_title' => '

', ) ); } add_action( 'widgets_init', 'wpb_widgets_init' );

在這段代碼中,我們註冊了兩個側邊欄。我們給它們命名和描述以便在插件界面識別。描述參數可用於告訴用戶這個側邊欄在主題中的顯示位置。

About the Author

Follow me


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
>