WordPress.org

Ready to get started?Download WordPress

Forums

customizing sidebar with javascript (1 post)

  1. shamratdewan
    Member
    Posted 1 year ago #

    Code reference:

    function sidebar_args( $name, $widget_class = 'widget', $title = 'h2' )
    {
    $id = strtolower( str_replace( ' ', '-', $name ) );

    return array(
    'name' => $name,
    'id' => $id,
    >>>Line-1 'before_widget' => '<div id="%1$s" class="'.$widget_class.'%2$s">',
    >>>Line-2 'after_widget' => '</div></span>',
    >>>Line-3 'before_title' => '<'.$title.' class="'.$widget_class.'%2$s" >',
    >>>Line-4 'after_title' => '</'.$title.'><span id="'.$idd.'" >',
    );
    }

    incase of line 1 the %2$s is printing widget-3 (where the number 3 is variable added to it)
    Output HTML>> <div class="widget-3" id="linkcat-9">

    BUT when i use the same code as in line-3 it outputs <h2 class="section%2$s">

    the above code is for sidebars and i want to add an ID on each element which is dynamic grows as the number of h2 section increases in my side bar. so that i can use the ID to use in JS to access each content of h2 element.

    can anybody suggest how to use %2$s or %1$s or add a dynamic id on each of the H2 in sidebar?

Topic Closed

This topic has been closed to new replies.

About this Topic