Home > Net >  php echo "<style>" posts css text
php echo "<style>" posts css text

Time:11-20

In one of my php functions I add some quite simple css. It worked very well until today. Actually the css is still doing his job, but in addition it prints in the middle of my layout whatever is written between the <style></style> tags - in my case it shows .element {display: none !important;} . My code:

echo'<style>.element {display: none !important;}</style>'; 

Has there been any update to php or WP that doesn't allow this anymore? Is there any other way to do this?

Thanks a lot for your help!

CodePudding user response:

I am not sure if it might change anything, but can you try print? Also I think if <style> is not within <head></head> it will not work.

CodePudding user response:

I found a working solution. Previously, I had a function in functions.php, which did some user type specific PHP and also CSS. Now I removed the CSS from functions.php and added it to header.php just before </head>. The function is in two places now, which I wouldn't prefer, but it works very well.

Still a riddle to me is, how the echo "<style>...</style>"; used to work in functions.php for approx. the last 6 months or so and then suddenly yesterday created mentioned issue.

Btw, I also tried ?><style>...</style><?php and print "<style>...</style>";. All created the same issue. Again, the "<style>" was not shown on the browser, only whatever was inside. Also, the CSS worked. Whatever, statements I entered was interpreted as correct CSS, but in addition also shown as text right between the layout. Here is an example source code at the browser at my enter image description here

  • Related