0

I have this code

a:after{
content url:(/path to my image/my_image.png)
  ......
}

and it works fine. But I am now migrating my site to WordPress. I can't use the WordPress function get_theme_file_uri(); to get my image path Or is there another alternative.

2
  • 2
    how is this a php question? There's only CSS here. Commented Nov 14, 2018 at 18:38
  • You need to add your PHP code when you tag PHP! Commented Nov 14, 2018 at 18:59

2 Answers 2

2

Unless you're running your CSS documents through a PHP eval() function (which you shouldn't do by most standards) there isn't a good way to execture PHP inside of CSS. The best way to solve your issue is linking directly to the image.

Assuming your directory structure is something like:

[..]
    [wp-admin]
    [wp-content]
        [uploads]
            [images]
               --my-image.jpg--
    [wp-includes]
    --other files--

You could use it by simply using a relative path to the file, like:

a::after {
    content: url(/wp-content/uploads/images/my-image.jpg);
}
Sign up to request clarification or add additional context in comments.

Comments

0

CSS urls are relative to the CSS file.

if you have structure like

..
images
    my_image.png
index.php
style.css

you can use a relative URL like:

a:after{
    content url:(images/my_image.png)
}

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.