1

I am trying to insert a shortcode inside CSS file but i am unable to achieve it. Don't know where I am going wrong.

I am inserting below code inside my style.css file:

div#cuzd-dispatch-general-v {
    display: <?php echo do_shortcode('[dispatch_date_hide]'); ?> ;
    }

OUTPUT:

div#cuzd-dispatch-general-v {
display: <?php echo do_shortcode('[dispatch_date_hide]');
}

Output as Image: http://oi61.tinypic.com/2uiyd4x.jpg

4
  • 1
    The css must be in a .php file. Commented May 28, 2015 at 10:38
  • 1
    You'd need to tell your webserver to process CSS as PHP. Instead, couldn't you just have multiple rules using your the shortcode as a CSS class, then add the class to the HTML based on the shortcode using PHP, or whatever templating you're using. Commented May 28, 2015 at 10:38
  • 1
    Probably your goal is to dynamically create a css file, since a css file itself cannot contain any dynamic elements like php code. You can do that by implementing a php file that outputs css rules (instead of the usual html markup). You then reference that php file just like any static css file. Commented May 28, 2015 at 10:40
  • This question has been asked a number of times in a number of different ways, on SO and on other websites. Commented May 28, 2015 at 13:04

2 Answers 2

2

add this code in your header.php inside <style> </style>

div#cuzd-dispatch-general-v {
    display: <?php echo do_shortcode('[dispatch_date_hide]'); ?> ;
}
Sign up to request clarification or add additional context in comments.

1 Comment

Sorry. I dont have much reputation. I tried but it failed.
2

PHP code cannot be interpreted inside a .css file so your php code will be showen as a plain text, add the part of your code in the style tag of your php file.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.