Hi @gyurmey – I asked @greenshady to take a look at this, and he shared that this function:
add_action( 'init', function() {
var_dump( wp_get_global_styles(array('color', 'background')) );
}, 99999 );
Gives this output:
string(32) "var( --wp--preset--color--base )"
If that doesn’t help to resolve your issue, it would be helpful if you could provide more context, such as a bigger piece of the relevant code. Thanks!
Hi @zoonini
Thank you for the response. However, this function doesn’t work.
As for the context, I’m just trying to get data from global styles when I change color in settings (screenshot).
Hi @gyurmey could you please copy a larger chunk of your code (including the function provided above) into a Pastebin or between code tags here in the forum? That way I can ask Justin to have a look to try to see why the code may not be working, since he tested it several times on his end and it worked well.
Could you also please let me know:
– What version of WordPress are you using?
– Does the issue occur when all plugins are deactivated?
– Is the issue present with Twenty Twenty-Two?
– Is the standalone Gutenberg plugin active, and if so, what version is it?
@zoonini, sorry for the delay.
This is my code snippet.
Input:
<style>
.content {
background-color: <?php echo (wp_get_global_styles(array('color', 'background'))); ?>;
}
<?php echo var_dump(wp_get_global_styles(array('color', 'background'))); ?>
</style>
Output:
<style>
.content {
background-color: var:preset|color|luminous-vivid-amber;
}
string(37) "var:preset|color|luminous-vivid-amber"
</style>
The problem occurs when the colors are based on CSS variables. When it gets a color from the colors picker, that’s fine.
– What version of WordPress are you using?
6.0.2 and 6.1-alpha-54226
– Does the issue occur when all plugins are deactivated?
Yes.
– Is the issue present with Twenty Twenty-Two?
Yes, and any other block theme.
– Is the standalone Gutenberg plugin active, and if so, what version is it?
Yes (14.1.1 and Gutenberg Nightly).
-
This reply was modified 3 years, 8 months ago by
Gyurmey.
-
This reply was modified 3 years, 8 months ago by
Gyurmey.
Hi @gyurmey – thanks for the larger piece of code as well as your testing specs.
Justin took a look and created this function for you. Let us know if this does the trick!
https://gist.github.com/justintadlock/ff27b00de0b28726b3336cde8d01806b
@zoonini, it works! Thank you very much for help.
@gyurmey Awesome! You’re very welcome, and I’ve passed along your thanks to Justin as well. 🙂