2016-03-04 51 views
1

我添加了一個新的工具條WordPress動態小部件 - 如何刪除標記和更改類名?

function child_register_sidebar(){ 
    register_sidebar(array(
     'name' => 'Social Media (Follow)', 
     'id' => 'sidebar-follow', 
     'description' => __('Widgets in this area will be shown on all posts and pages.', 'theme-slug'), 
     'before_widget' => '', 
     'after_widget' => '', 
     'before_title' => '', 
     'after_title' => '', 
    )); 

} 

在我的模板,

<?php if (is_active_sidebar('sidebar-follow')) { ?> 
    <div class="follow-container"> 
     <?php dynamic_sidebar('sidebar-follow'); ?> 
    </div> 
<?php } ?> 

結果:

<div class="follow-container"> 
     <div class="textwidget"> 
      <a href="[full link to your Twitter]"> 
       <img title="Twitter" alt="Twitter" src="https://socialmediawidgets.files.wordpress.com/2014/03/01_twitter1.png" width="35" height="35" /> 
      </a> 
     </div> 
</div> 

如何刪除<div class="textwidget">或更改類的名稱別的東西?

回答

3

嘗試使用刪除textwidget這個代碼,並在functions.php中運用自己的類

function register_my_widgets() { 
    register_sidebar(array(
     'name' => 'test-widget', 
     'id' => 'test-widget', 
     'description' => __('Widgets in this area will be shown on all posts and pages.', 'theme-slug'), 
     'before_widget' => '', 
     'after_widget' => '', 
     'before_title' => '', 
     'after_title' => '', 
    )); 
    register_widget('My_Text_Widget'); 
} 

class My_Text_Widget extends WP_Widget_Text { 
    function widget($args, $instance) { 
     extract($args); 
     $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base); 
     $text = apply_filters('widget_text', empty($instance['text']) ? '' : $instance['text'], $instance); 
     echo $before_widget; 
     if (!empty($title)) { echo $before_title . $title . $after_title; } ?> 
      <?php echo !empty($instance['filter']) ? wpautop($text) : $text; ?> 
     <?php 
     echo $after_widget; 
    } 
} 
+0

它刪除整個小部件內容。結果:'

' – laukok

+0

它很實用。謝謝! – laukok

1

'class' => ''添加到您的參數註冊側邊欄如果你想刪除類或'class' => 'myClass'如果你想使用你的。

註冊小工具會是這個樣子:

function child_register_sidebar(){ 
    register_sidebar(array(
     'name' => 'Social Media (Follow)', 
     'id' => 'sidebar-follow', 
     'description' => __('Widgets in this area will be shown on all posts and pages.', 'theme-slug'), 
     'before_widget' => '', 
     'after_widget' => '', 
     'before_title' => '', 
     'after_title' => '', 
     'class' => 'myClass' 
    )); 

} 
+0

已嘗試,但不起作用。 – laukok

+0

哦,對不起。 textwidget來自我認爲的WordPress。你只註冊一個側邊欄,並把標準的WP Widget,不是你自己的權利? – 2016-03-04 09:05:47

+0

不是我自己的。它由WP默認生成。 – laukok

相關問題