WordPress.org

Ready to get started?Download WordPress

Forums

Need PHP help to fix widget area (4 posts)

  1. nicnack
    Member
    Posted 1 year ago #

    Hi!

    Below is a script that creates a widget area. Any widget that is added into this area is contained within a simple <div></div> tag.

    I need the script to generate a unique ID per div (widget) created.. so that it would be like:
    <div id="name1">widget 1 here</div>
    <div id="name2">next widget here</div>
    <div id="name1">another widget here</div>
    etc..

    here is the script:

    function arphabet_widgets_init() {

    register_sidebar( array(
    'name' => 'Home Footer',
    'id' => 'home_bottom_1',
    'before_widget' => '<div>',
    'after_widget' => '</div>',
    'before_title' => '<h2 class="rounded">',
    'after_title' => '</h2>',
    ) );
    }
    add_action( 'widgets_init', 'arphabet_widgets_init' );

    any suggestions?
    thanks!!

  2. andrewmills
    Member
    Posted 1 year ago #

    Maybe I'm not understanding what you are trying to accomplish, but doesn't the register_sidebars function already let you do that with the -$i bit in the $args array?

  3. nicnack
    Member
    Posted 1 year ago #

    I dont know how to write this out, so can you show me what you mean? basically the goal would be to give each ID a unique variable

  4. alchymyth
    Forum Moderator
    Posted 1 year ago #

    example:

    'before_widget' => '<div id="%1$s">',

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.