如何在WordPress中为自定义边栏添加一个类
问题描述:
我刚刚了解了如何创建自定义WordPress主题。我想为我的侧栏指定一个类来创建样式,但是我没有在网上找到任何解释如何执行此操作的内容。我加入到我的functions.php文件中的代码注册我的侧边栏是:如何在WordPress中为自定义边栏添加一个类
if (function_exists('register_sidebar')) register_sidebar(array( 'id' => 'sidebar-1', 'description' => __('Add widgets here to appear in your sidebar.', 'twentysixteen'), 'before_widget' => '', 'after_widget' => '', 'before_title' => '', 'after_title' => '', ));
我加入到我的sidebar.php文件中的代码是:
<?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar()) : ?>
<?php endif; ?>
任何帮助将不胜感激!
答
使用before_widget和after_widget添加包装。
答
register_sidebar(array(
'name' => esc_html__('Sidebar', 'twentysixteen'),
'id' => 'sidebar-1',
'description' => 'Add widgets here to appear in your sidebar.',
'before_widget' => '<aside id="%1$s" class="widget custom-class %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title custom-class">',
'after_title' => '</h2>',
));
在functions.php文件试试这个