Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

This question already has an answer here:

I created a plugin and use php file as stylesheet file

PHP style sheet file:

<?php
    header('Content-type: text/css; charset: UTF-8');
    $x_position = 0;
    $y_position = -40px;
?>
.blugin_box{
    width:140px;
    height:140px;
    background:url("/mysite/wp-content/plugins/myimgfolder/my_img.png") no-repeat $x_position $y_position;
}

It works well , but when I try to use plugins_url() as below, stylesheet stop loading

background:url(plugins_url()."/myimgfolder/my_img.png") no-repeat $x_position $y_position;

How can I make it work?

share|improve this question
add comment

marked as duplicate by toscho Nov 21 '13 at 13:38

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

Try

background:url(<?php echo plugins_url().'/myimgfolder/my_img.png'; ?>) no-repeat <?php echo $x_position.' '.$y_position; ?>;

It will allow you to echo the PHP elements into your style.

EDIT:

You also need to close the file, you're trying to mix unwrapped PHP with your CSS. Your PHP variables aren't escaped either. I've tested the code below, and it works fine:

<?php
    header('Content-type: text/css; charset: UTF-8');
    $x_position = 0;
    $y_position = '-40px';
?>
.blugin_box{
    width:140px;
    height:140px;
    background:url(<?php echo plugins_url().'/myimgfolder/my_img.png'; ?>) no-repeat <?php echo $x_position.' '.$y_position; ?>;
}

I suggest using:

error_reporting(E_ALL);
ini_set('display_errors', 1);   

While you're debugging so that you can see any PHP errors on screen, or check your log files :-)

share|improve this answer
    
I tried your advice but it didn't work and file stop loading, as I mentioned in my question file stop loading if I add plugins_url() –  usama sulaiman Nov 21 '13 at 13:29
    
Updated the answer, tested and it works. Try enabling errors to your display in PHP to see where your errors are –  ThePHPUnicorn Nov 21 '13 at 16:55
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.