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
Thinking about a better way of doing dynamic CSS for shortcodes #62
Comments
How they do the enqueue of css and dynamic css? |
maybe with CSSOM https://github.com/israelidanny/veinjs |
It's almost the same as inline css
|
@moldcraft Not quite. There can be LOTS of css and the flexibility is going down very fast. @llemurya It is better to add it from backend. Doing this operation from JS in the frontend at a regular basis can:
|
I am using the head embed , no inlines at all because as you said they are very ugly and unorganized ,
I dont see problem in there because you have min one styleshet in your theme so why not use that , I went one step further and created a CSS collect class that I am using in each shortcode
where add_css is the var that holds the dinamic css for the shorcode than I call the wp_add_inline_style only once in the hooks
this way I ednup with nice and clean embed , that I can also compress to a file etc. which changes depending on where you are and if the shortcode is used or not |
Sometimes when you are loading it TOO early, the theme css is not yet loaded, for some reason. We need a bulletproof one that will be around 100%. That's what I'm looking for now. @danyj Yeah, we're also using this technique internally. |
@andreiglingeanu well , WP never introduced something like this which would be perfect for your issue and everyone else so we are stuck on wp_add_inline_style or the ugly inlines. |
Okay, I figured it out how it works. The good news are that you can insert any shortcode directly in the post editor, and this will handle it accordingly. The bad ones consist of the fact that you can't just insert them anywhere else without much work. I'll try to categorise all the use cases below and the work you have to do for each of them.
Notes: The parts with ❌ you're supposed to handle by yourself. With To conclude, there's no way of getting an universal solution for all of this. That's it, we tried and we failed. |
@andreiglingeanu , can you provide the snippets for 2 and 3 , for assets and dynamic css that we can use please. |
@danyj Will do. Actually I'll link you to the docs entry for this that will be added later. |
Upd. Because of this now shortcodes within other PB Shortcodes are handled correctly (use case 2). Table below also update. Detailed documentation to come. PS: Can anyone help with some CSS? Pull requests welcome! |
@andreiglingeanu about the static and dynamic anywhere , this is my notification shortcode static isnt there any way for you to add a hook or custom term to the post once the shortcode is inserted via editor so that I could do something like this
I mean , I can make that function available in my helpers.php and call it where ever you give the hook, it does not have to be bound to static.php since I use same coding pattern in every shortcode. |
@danyj Do you mean dealing about 3rd use case? |
yes, if at all possible, il bend over and backwards since I am not done and that feature would mean alot. |
Let's say you have an editor in TS and you can get it's result like this: $content = fw_get_db_settings_option('editor');
// add this HTML somewhere in your templates, like this
echo do_shortcode($content); Now you're done with first phase - add_action( 'wp_enqueue_scripts', '_handle_my_editor_statics' );
function _handle_my_editor_statics () {
// get same content once again
$content = fw_get_db_settings_option('editor');
// then use it to load all of the statics for your shortcodes
// both `static.php` and dynamic ones
fw_ext_shortcodes_enqueue_shortcodes_static(
$content
);
} And don't forget to add And you're all covered. |
ok than that is the solution 👍 , why are you marking it as not possible? |
Yeah, I really meant that you have to do some more work in order to get this done correctly. |
I'm sure none of us mind the work when something like this is in question. we waited to long for the "Holy Andrei" :)))) |
@danyj Yeah) Let me know how it goes, especially if it goes wrong. |
@andreiglingeanu , just tested the custom dynamic CSS addon #62 (comment) and works like charm! THANK YOU!!!! |
@danyj Great news, I've also tested it a lot and looks like it works fine. It may also appear some small flaws, and I am aware of that. Just keep me in sync with all of this. I should really finish the docs for this one, but didn't really had time for this. |
Hi there, hi @andreiglingeanu Regards. |
Not impossible. We just need the right guy to come up with a pull request for that. I won't even try to do this for now.
That's also possible. You'll just have to think about some other way to visualise your shortcodes in textarea -- your business.
It is working only on tinyMCE for now. But there's nothing stopping you from implementing the UI in some different way. Good luck.
It won't. |
Guys, I mean I use the page builder mostly and do a lot of changes to sections, columns, etc. and it bothers me that styles are in head of HTML and not in files. Why not create dynamic css files on save? One for section, another for columns, based on how many shortcodes are used on a specific page. And display that specific CSS files for that specific page? Or ... add extra option to options
Let's parse each option and read the value and in_css. And based on this generate a dynamic css file. Just ideas :) |
First, I would like to know what techniques do you really use?
The most simple one is of course using
style
attribute, like this:I would simply skip this idea because it is obvious and HTML looks very ugly.
Next one, as described here: You have to hook onto an action and then call
wp_add_inline_style
function. The problem with this is that you are committing yourself to one specific css file because of the waywp_add_inline_style
works.While doing WP-Shortcodes, I've noticed a big problem with this. The dynamic styles for each of the shortcode you're inserting into post editor (or any
wp-editor
) won't be included.The thing we adhered to is that
wp-editor
won't include Unyson button by default. That's because you'll have to do applydo_shortcode
function to the result you're receiving fromwp-editor
. And also call a helper that we'll implement later that will include all the dynamic CSS.The problem is that this will introduce two problems:
wp-editor
<style>
tag besides each included shortcodeThe second one is most annoying.
Shortcodes from post editor can be handled a bit more easily -- without developer's implication.
Let me know what you think about all of this.
The text was updated successfully, but these errors were encountered: