0

When calls theme's style.css file with add_editor_style inside gutenberg, background images are not loading properly.

Lets say:

#intro {
    background: url(assets/main.png) ;
}

Its working properly on front-end like:

mydomain.com/wp-content/themes/mytheme/assets/main.png

But when in gutenberg, WordPress tries to load:

mydomain.com/wp-admin/assets/main.png

Am i missing something?

  • Is there a reason you do not want to set the full relative path in style.css? Have you tried #intro { background: url('/wp-content/themes/mytheme/assets/main.png') ;} – Anthony D Jan 9 at 14:47
  • It can be in subfolder installation – Ünsal Korkmaz Jan 10 at 15:06
0

You can load the css via PHP instead ,

add_action('wpmm_head', 'wpmm_custom_css');

    function wpmm_custom_css(){
     echo '<style>
           #intro{
    '.get_template_directory_uri().'/assets/main.png;
           }
           </style>';
    }
| improve this answer | |
  • You can't always know all images tbh. This is a problem that needs automatic fix – Ünsal Korkmaz Jan 13 at 8:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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