I'm developing a Wordpress theme that allows a client to upload their own header background image. But I don't want the image to load for mobile users. Here is what's working for me right now:
<div class="header" style="
@media (min-width: 676px) {
background-image: linear-gradient(to right, rgba(1, 1, 1, 0.7), rgba(1, 1, 1, 0.1) 35%),
url('<?php header_image(); ?>');
}
">
This works, but it's a lot of inline styling. Is there a way to avoid having so much inline css? Here's another method I tried that DIDN'T work:
function header_image_style() {
$header_image = header_image();
return "<style type='text/css'>
.header{
background-image:
linear-gradient(to right, rgba(1, 1, 1, 0.7), rgba(1, 1, 1, 0.1) 35%),
url('".$header_image."');
}
</style>";
}
This method only outputs the $header_image url to the page when header_image_style(); is called, and ignores all the other css. What is the best-practice method to achieve what I'm doing?
header_image_style();before any of the other normal stylesheets, but that method is still not working. It only returns the value of$header_imageand ignores the<style>tag and the css within it.echo header_image_style();?<style>tag with the css, but the url value from$header_imageis omitted from the background image property, and displayed as a string above the<style>tag. Like this:http://...bg.jpg <style type="text/css"> .header{ background-image: url('');} </style>