Can I use PHP inside CSS pseudo class












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.










share|improve this question




















  • 2





    how is this a php question? There's only CSS here.

    – Funk Forty Niner
    Nov 14 '18 at 18:38













  • You need to add your PHP code when you tag PHP!

    – Ashouri
    Nov 14 '18 at 18:59
















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.










share|improve this question




















  • 2





    how is this a php question? There's only CSS here.

    – Funk Forty Niner
    Nov 14 '18 at 18:38













  • You need to add your PHP code when you tag PHP!

    – Ashouri
    Nov 14 '18 at 18:59














0












0








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.










share|improve this question
















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.







css wordpress






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 19:00







foliwe83

















asked Nov 14 '18 at 18:30









foliwe83foliwe83

7711




7711








  • 2





    how is this a php question? There's only CSS here.

    – Funk Forty Niner
    Nov 14 '18 at 18:38













  • You need to add your PHP code when you tag PHP!

    – Ashouri
    Nov 14 '18 at 18:59














  • 2





    how is this a php question? There's only CSS here.

    – Funk Forty Niner
    Nov 14 '18 at 18:38













  • You need to add your PHP code when you tag PHP!

    – Ashouri
    Nov 14 '18 at 18:59








2




2





how is this a php question? There's only CSS here.

– Funk Forty Niner
Nov 14 '18 at 18:38







how is this a php question? There's only CSS here.

– Funk Forty Niner
Nov 14 '18 at 18:38















You need to add your PHP code when you tag PHP!

– Ashouri
Nov 14 '18 at 18:59





You need to add your PHP code when you tag PHP!

– Ashouri
Nov 14 '18 at 18:59












2 Answers
2






active

oldest

votes


















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);
}





share|improve this answer































    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)
    }





    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53306652%2fcan-i-use-php-inside-css-pseudo-class%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      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);
      }





      share|improve this answer




























        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);
        }





        share|improve this answer


























          2












          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);
          }





          share|improve this answer













          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);
          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 14 '18 at 18:53









          RyanRyan

          3169




          3169

























              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)
              }





              share|improve this answer




























                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)
                }





                share|improve this answer


























                  0












                  0








                  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)
                  }





                  share|improve this answer













                  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)
                  }






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 14 '18 at 18:36









                  Eriks KlotinsEriks Klotins

                  1,3611517




                  1,3611517






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53306652%2fcan-i-use-php-inside-css-pseudo-class%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Xamarin.iOS Cant Deploy on Iphone

                      Glorious Revolution

                      Dulmage-Mendelsohn matrix decomposition in Python