How to edit widgets in WordPress

In the Appearance -> Widgets menu there is a list of widgets that you can drag and drop to show in the sidebar.Where

In the Appearance -> Widgets menu there is a list of widgets that you can drag and drop to show in the sidebar.

Where is the HTML/PHP code for these custom widgets?

I've been on WordPress's Function Reference but couldn't find anything. Surely these widgets must be pulled from a HTML/PHP template.

The reason I want to know is the widget titles by default are <h3> tags and i want to change them to <h5> tags. Also i need to add some <hr />'s and other things.

I've looked in the theme/includes/widgets.php file but found nothing.

I'm using a copy of Twenty Eleven to modify my theme by the way.

The code in theme/sidebar.php is for (!dynamic_sidebar()), however my sidebar is dynamic so this code is useless.

In the Appearance -> Widgets menu there is a list of widgets that you can drag and drop to show in the sidebar.

Where is the HTML/PHP code for these custom widgets?

I've been on WordPress's Function Reference but couldn't find anything. Surely these widgets must be pulled from a HTML/PHP template.

The reason I want to know is the widget titles by default are <h3> tags and i want to change them to <h5> tags. Also i need to add some <hr />'s and other things.

I've looked in the theme/includes/widgets.php file but found nothing.

I'm using a copy of Twenty Eleven to modify my theme by the way.

The code in theme/sidebar.php is for (!dynamic_sidebar()), however my sidebar is dynamic so this code is useless.

Share Improve this question edited Feb 7, 2014 at 14:07 Pat J 12.5k2 gold badges28 silver badges36 bronze badges asked Jan 16, 2012 at 12:20 AlexMorley-FinchAlexMorley-Finch 1711 gold badge1 silver badge3 bronze badges 2
  • Perhaps your looking for this: stackoverflow/a/2293494 – Asko Commented Jan 16, 2012 at 12:24
  • dynamic_sidebar() will do one of two things when called, it will either echo the sidebar, or return false. So if( !dynamic_sidebar() ) will either echo the sidebar, or do some sort of fallback. – mor7ifer Commented Jan 16, 2012 at 13:46
Add a comment  | 

2 Answers 2

Reset to default 10

The WordPress Widgets API is how various widgets are created and sidebars registered.

When creating a new widget there are variables that can be added to any widget. Those get their value from the register_sidebars arguments.

args (string/array) (optional)
Builds Sidebar based off of 'name' and 'id' values. Default: None
name - Sidebar name.
id - Sidebar id.
before_widget - HTML to place before every widget.
after_widget - HTML to place after every widget.
before_title - HTML to place before every title.
after_title - HTML to place after every title.

Example:

<?php
    add_action( 'widgets_init', 'prefix_register_sidebars' ); 
    function prefix_register_sidebars() {
         $args = array(
         'name' => 'My Sidebar',
         'id'   => 'my-sidebar',
         'before_widget' => '<div id="%1$s" class="widget %2$s">',,
         'after_widget'  => '</div><hr />',
         'before_title'  => '<h5 class="widgettitle">',
         'after_title'   => '</h5>'
         );
      register_sidebars( $args );
   }

Example Widget:

class MY_Widget extends WP_Widget {
    function my_widget( $args, $instance ) {
         $widget_ops = array(
         'description' => 'My Widget Description'
         );
        parent::WP_Widget(false, 'My Widget Name', $widget_ops );
    }
    function widget() { // This controls the display of the widget
    $title = 'My Widget Title';

    echo $before_widget;  // Outputs the the 'before_widget' register_sidebars setting
    echo $title;         //Will be wrapped in the 'before_title' and 'after_title' settings
    echo '<p>This is my widget output</p>';
    echo $after_widget;  //Outputs the 'after_widget' settings
    }
}
add_action( 'widgets_init', 'prefix_register_widgets' );
function prefix_register_widgets() {
    register_widget( 'my_widget' );
}

it is in the functions.php

function twentyeleven_widgets_init() {

register_widget( 'Twenty_Eleven_Ephemera_Widget' );

register_sidebar( array(
    'name' => __( 'Main Sidebar', 'twentyeleven' ),
    'id' => 'sidebar-1',
    'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    'after_widget' => "</aside>",
    'before_title' => '<h3 class="widget-title">',
    'after_title' => '</h3>',
) );

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745543678a4632240.html

相关推荐

  • How to edit widgets in WordPress

    In the Appearance -> Widgets menu there is a list of widgets that you can drag and drop to show in the sidebar.Where

    6小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信