在<div></div>内换行边栏

时间:2021-11-03 作者:Filippo

我询问是否可以在<div class="customdiv"></div>.是否有任何说明要添加到函数中。php文件?非常感谢。

像这样:

I\'ve created this sidebar (which contains widgets):
    // ATTIVITA - widgets   
        register_sidebar(
        array (
            \'name\' => __( \'ATTIVITA prenotabili\', \'your-theme-domain\' ),
            \'id\' => \'<div id="testimonial-slider">\',
            \'description\' => __( \'ATTIVITA prenotabili\', \'your-theme-domain\' ),
            \'before_widget\' => \'<div class="widget-content">\',
            \'after_widget\' => \'</div>\',
            \'before_title\' => \'<h3 class="widget-title">\',
            \'after_title\' => \'</h3>\',
        )
    );
//fine
我想把它包装成一个你认为可能吗?非常感谢。

2 个回复
SO网友:BrianVan

更新:现在帖子已经澄清,在自定义侧栏声明中,将这些行更改为以下内容(这也保留了现有包装,建议保留在中,除非您知道要删除它们):

            \'before_widget\' => \'<div class="customdiv"><div class="widget-content">\',
            \'after_widget\' => \'</div></div>\',

我假设您正试图编辑一个系统加载的侧栏。在函数中尝试此代码。php。要使用此工具编辑的提要栏的前端将有一个id,您可以使用浏览器中开发人员工具中的标记检查器找到该id,一旦有了该id,您就必须将下面第五行上的“specific\\u sidebar\\u id”替换为要更改的提要栏的id。

function customize_my_sidebar() {

    global $wp_registered_sidebars;

    $key = array_search(\'specific_sidebar_id\', array_column($wp_registered_sidebars, \'id\'));

    $wp_registered_sidebars[$key][\'before_widget\'] = \'<div class="customdiv">\';
    $wp_registered_sidebars[$key][\'after_widget\'] = \'</div>\';

}

add_action( \'wp_loaded\', \'customize_my_sidebar\' );
如果您正在注册一个全新的侧边栏,您应该自定义;before\\u widget“;和;“after\\u widget”;在调用register\\u sidebar()时的定义中,如下所述:https://developer.wordpress.org/reference/functions/register_sidebar/

SO网友:cjbj

从您的问题中,我了解到您希望将完整的侧栏包装在div, 而不是侧边栏中的单个小部件。这在注册阶段是不可能的。但是,这在渲染阶段是可能的。在主题中,这是通过函数完成的dynamic_sidebar.

现在,当您查看该函数时,您将看到在呈现小部件之前和之后定义了一些操作,即dynamic_sidebar_beforedynamic_sidebar_after. 您可以按如下方式使用:

add_action (\'dynamic_sidebar_before\',\'wpse397644_before_sidebar\');
function wpse397644_before_sidebar ($index, $has_widgets) {
  if ($has_widgets) echo \'<div class="customdiv">\';
  }

add_action (\'dynamic_sidebar_after\',\'wpse397644_after_sidebar\');
function wpse397644_after_sidebar ($index, $has_widgets) {
  if ($has_widgets) echo \'</div>\';
  }

相关推荐

从SANITIZE_html_CLASS排除URL

我搜索了类似的问题,但什么也没找到。我编写了一个元框,用于添加自定义URL,这些URL会添加到单个帖子的按钮中,但当URL添加到编辑帖子屏幕上的元框字段并保存时,它会将URL从以下内容中删除:http://example.com 对此:httpexamplecom 我假设由于sanitize\\U html\\U classes函数与save\\U post函数一起使用,如下所示:add_action( \'save_post\', \'projecturl_save\', 1, 2