Can anybody explain me what's %1$s ??? (2 posts)

  1. Zambrano Sergio
    Posted 5 years ago #

    Can you shortly explain me or lead me to the answer about how to access those variables with %#… ???

    I'd like to get widget number inside a sidebar (or TEXT widget instance inside that sidebar, since that sidebar will only contain text widgets), but I haven't found info about those in the codex and the whole internet.

    WP codex uses this example, but both the id and class give me the basename plus the widget number. I only need the widget number, which I think is very useful.
    I tried $i, but it doesn't do a thing.

    <?php $args = array(
    	'name'          => sprintf(__('Sidebar %d'), $i ),
    	'id'            => 'sidebar-$i',
    	'description'   => ''
    	'before_widget' => '<li id="%1$s" class="widget %2$s">',
    	'after_widget'  => '</li>',
    	'before_title'  => '<h2 class="widgettitle">',
    	'after_title'   => '</h2>' ); ?>
  2. esmi
    Forum Moderator
    Posted 5 years ago #

    %1$s is a text-substitution rather like a preg_replace. I'd suggest examining the register_sidebar function in wp-includes/widgets.php to see how the text substitution works.

Topic Closed

This topic has been closed to new replies.

About this Topic