Apply code for all else first block

I have this code for sidebar in WordPress :-

 register_sidebar(array(
'name' => 'Main sidebar',
'description' => 'main sidebar.',
'before_widget' => '<div id="blocks" class="siderbar box_outer %2$s" style="visibility: hidden;"><div class="widget">',
'after_widget' => '</div></div>',
'before_title' => '<h3 class="widget_title">',
'after_title' => '</h3><div class="wid_border"></div>'
  ));

In this cod will add every widget attribute style="visibility: hidden;", but i need to add this attribute for all widget else first widget.

Read More

How can do that by php or JQuery.

Related posts

Leave a Reply

1 comment

  1. I believe that what you want to do would better be done with CSS rules in your stylesheet rather than with an embedded style tag that you dynamically manipulate with PHP.

    Remove style="visibility: hidden;" from your register_sidebar argument and use something like the following instead (Proof of Concept):

    <html>
    <head>
      <style>
        .aclass { visibility:hidden }
        .aclass:first-child { visibility:visible }
      </style>
    </head>
    <body><?php
      for ($i = 1; $i < 5; $i++) {
        echo '<div class="aclass">'.$i.'</div>';
      } ?>
    <body>
    </html>
    

    That is purely to make the two necessary rules apparent. You can run that code to get a feel for things if you’d like. You will need to swap aclass for the class you need to target– either siderbar or box_outer I presume. And you probably want to write the rules into your main stylesheet.