php 注册侧边栏

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 注册侧边栏相关的知识,希望对你有一定的参考价值。

<?php

/**
 * Register widget area.
 *
 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 */
function theme_widgets_init() {
	register_sidebar( array(
			'name'          => esc_html__( 'Sidebar', 'theme' ),
			'id'            => 'sidebar-1',
			'description'   => esc_html__( 'Add widgets here.', 'theme' ),
			'before_widget' => '<section id="%1$s" class="widget %2$s">',
			'after_widget'  => '</section>',
			'before_title'  => '<h2 class="widget-title">',
			'after_title'   => '</h2>',
		)
	);
	register_sidebar( array(
			'name'          => esc_html__( 'Header Ad Area', 'theme' ),
			'id'            => 'header-1',
			'description'   => esc_html__( 'Add advert widget here.', 'theme' ),
			'before_widget' => '<section id="%1$s" class="widget %2$s">',
			'after_widget'  => '</section>',
			'before_title'  => '<h2 class="widget-title">',
			'after_title'   => '</h2>',
		)
	);
	register_sidebar( array(
			'name'          => esc_html__( 'Header Social Icons', 'theme' ),
			'id'            => 'header-social',
			'description'   => esc_html__( 'Add social media widgets here.', 'theme' ),
			'before_widget' => '<section id="%1$s" class="widget %2$s">',
			'after_widget'  => '</section>',
			'before_title'  => '',
			'after_title'   => '',
		)
	);
}
add_action( 'widgets_init', 'theme_widgets_init' );

以上是关于php 注册侧边栏的主要内容,如果未能解决你的问题,请参考以下文章

php 注册一个新的侧边栏

PHP 注册一个新的侧边栏

PHP 为Thesis注册新的侧边栏

如何在 WordPress 中将类添加到自定义侧边栏

注册侧边栏

当侧边栏在 single.php 中时,侧边栏分页不显示