Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Media query instead of media type in link tag #9352

Closed
szepeviktor opened this issue Oct 13, 2015 · 10 comments
Closed

Media query instead of media type in link tag #9352

szepeviktor opened this issue Oct 13, 2015 · 10 comments

Comments

@szepeviktor
Copy link
Contributor

Although it is valid HTML WordPress expects media type in wp_enqueue_style/wp_register_style.

<link rel='stylesheet' id='woocommerce-smallscreen-css'  
href='//subtwo.wp/static/plugins/woocommerce/assets/css/woocommerce-smallscreen.css?ver=2.4.7' 
type='text/css' media='only screen and (max-width: 768px)' />

Please consider using only media type.

Use case: W3 Total Cache merges small screen and desktop CSS files.

I know it is a caching consideration to use media query here.

@jameskoster
Copy link
Member

Not really sure what you're asking us to do here?

@szepeviktor
Copy link
Contributor Author

Could you go media="screen" ?

https://codex.wordpress.org/Function_Reference/wp_enqueue_style

$media
(string|boolean) (optional) String specifying the media for which this stylesheet has been defined. Examples: 'all', 'screen', 'handheld', 'print'. See this list for the full range of valid CSS-media-types.

And handle small screen stylesheet a different way.

@claudiosanches
Copy link
Contributor

Feel free to use our woocommerce_enqueue_styles filter.

https://github.com/woothemes/woocommerce/blob/master/includes/class-wc-frontend-scripts.php#L54

But this is valid HTML and displays to be read only by small screens.

Here for your reference: http://www.w3.org/TR/css3-mediaqueries/

@szepeviktor
Copy link
Contributor Author

Thank you.
I do understand that the output is valid HTML but WordPress core lacks the feature of media queries. Only media type is allowed in media.

For googlers:

  1. You exclude woocommerce-smallscreen.css from minification/combining
  2. Replace it in the above filter with
@media only screen and (max-width: 768px) {
    @import 'woocommerce-smallscreen.css';
}

@claudiosanches
Copy link
Contributor

WordPress accept any media queries, however it seems that the docs needs some update.
See how works the class responsible for this:

https://core.trac.wordpress.org/browser/tags/4.3.1/src/wp-includes/class.wp-styles.php#L0

@szepeviktor
Copy link
Contributor Author

Yes.
Please pay attention to that all plugins are written based on the docs.
For example W3 Total Cache.

@claudiosanches
Copy link
Contributor

@szepeviktor this is a W3 Total Cache issue, not a WooCommerce or WordPress issue.

@claudiosanches
Copy link
Contributor

But, I'll update the docs for you @szepeviktor ;)
Since anyone can update the WordPress docs.

@szepeviktor
Copy link
Contributor Author

Thank you.
I think W3TC is core conformant.
https://wordpress.org/support/topic/woocommerce-media-query

@claudiosanches
Copy link
Contributor

@szepeviktor good luck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants