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.