Envato can allow inline CSS for background-image but reviewers comment is confusing me

I have faced a problem. I have converted a theme for ThemeForest market place. But my theme got soft reject and reviewer mentioned this issue

Scripts and styles should not be hardcoded anywhere in your theme or added any other way but with wp_enqueue_* hook and to be added from the functions file. This includes custom JS/CSS. For inline styles use: https://developer.wordpress.org/reference/functions/wp_add_inline_style/ and for scripts https://developer.wordpress.org/reference/functions/wp_add_inline_script/"

After that, I have found some inline CSS on my theme which is used for background-image. Then I have solved inline CSS issue by using flollowing link functions wp_add_inline_style(), get_theme_mod() and set_theme_mod().

But in the Envato help author page can allow inline CSS for background-image. Which is :

Described in the below link

Now my question is- “I have used inline CSS background-image (post-thumbnail) for blog post which are dynamic. If I follow Envato reviewer instruction then I can’t use inline CSS background-image for blog post but Envato help author page can permitted inline CSS for only background-image.”

What should I do now?

You have to add all your CSS with wp_enqueue_* , no inline CSS is accepted, basically, you have to add all your CSS in CSS files and use wp_enqueue_* to include them in your theme.

Inline CSS for some dynamic content like post thumbnails is completely legit. Just make sure to explain it in the message for the reviewer when you resubmit.
But make sure that you do not use inline CSS in other context where it may not be allowed. It is likely the reviewer meant something else, not the background-image one, so really double check your code.

You are wrong, it is clearly stated in the official Envato requirements posted by OP above that it is allowed in some cases.

I remember that I had this issue and got soft reject until I moved the CSS in class always soft reject, maybe I am wrong but to be safe I would move everything to CSS files just to be sure…

Well, it was definitely not a background-image CSS exception in your case then, I mean how exactly you want to add background-image CSS for post thumbs into external CSS file? That’s nonsense.

1 Like

Hi, you can use JS to add CSS styles (as many JS libs do), but, no PHP inline CSS is allowed.

Still, if you want it in PHP you’d have to use wp_add_inline_style within the wp_enqueue_scripts. There’s a really nice sample with the TwentyTwenty theme you can check out.

Thanks!

OMG, guys, please STOP spreading misinformation, and READ the official Envato requirements before you join the discussion on this:

Dynamic styling must be added via wp_add_inline_style() with the exception of adding a background image to an element. In this instance, the following would be permitted:

 <div id="header-background" style="background-image: url( <?php echo esc_url( 
'$header-background' ); ?> );"></div>

Source:

Adding background-image CSS via inline code is completely fine, as it should be, because it is the most efficient way of doing this.

2 Likes