PHP snippet shortcode only works once

[ad_1]

Hello,

just wondering why my little php snippet only works once.

Added this small script inside a Gutenberg post loop area to add an ACF variable to css.

<?php while (have_posts()) : the_post(); ?>
   <style type="text/css">
   li.post-<?php echo esc_attr( get_the_ID() ); ?> {    
       some css here
   }
   </style> 
<?php endwhile; ?>

Adding the script as a shortcode inside the post loop element works fine on archive template with twenty twenty four.

But if i try to add the script shortcode inside another post loop element on a page, it doesn’t show up and no <style> is added. Seems it code only works once…

I’ve already tried to use it as a universal snippet with an ending ‘?>’
No condition logics.

Can you help? Many thanks in advance!

Best, Sven

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer