Rob Myrick
Rob Myrick

Reputation: 859

Using CSS and PHP Together

I have built a Wordpress plugin that requires to me to add CSS styles through the plugin's PHP file.

Is there a better way of doing this? I can see this getting out of hand if not done properly.

function flags() {  

 <style type="text/css">

  <?php if(get_option('display')=='Vertical') { ?>
    <?php if (get_option('language_option')=='specific') { ?>
        #flags {display:none !important; }
    <?php } ?>
        p.hello { font-size:12px; color:darkgray; }
  <?php } ?>

 </style>     
<?php } 
}   

Upvotes: 1

Views: 145

Answers (1)

nice ass
nice ass

Reputation: 16729

If there isn't much CSS, a better way is to add body classes that allow you to target your selectors only when they are present:

<body class="display-vertical">    
  ...

And move the CSS from inline to the stylesheet:

.display-vertical #flags{
   ...
}

Upvotes: 1

Related Questions