I want to learn more about elementor theme development. I have set up header.php, footer.php and index.php and created a new page via wordpress admin. I added a new widget, which show correctly in my editor, but when i publish the page, my global elementor styles are not applied. I tried searching the documentation and googling, but found nothing. I assume i need to call some elementor function to make this work. What am i missing?
For example: –e-global-color-primary is undefined
Here are my files:
header.php
<!DOCTYPE HTML>
<html>
<head>
</head>
<body <?php body_class(); ?>>
<?php wp_head(); ?>
footer.php
<?php wp_footer(); ?>
</body>
</html>
index.php
<?php get_header(); ?>
<?php the_content(); ?>
<?php get_footer(); ?>
2
Answers
I have done some extra research on this. It is a bug in elementor and is not fixed yet. I ended up doing a workaround. It is provided below if anyone needs it.
If you look at your browser developer tools inspector and take a look at
.elementor-kit-X {...}
(where X is a number set by elementor) at the bottom of your CSS declarations, you’ll see all of the specified__globals__
, which includes your font families as well.Take this control as an example:
Next, add this near the top of your
protected function render(){...}
:echo'<pre>';print_r($settings);echo'</pre>';
Go into edit mode, and specify a non-global color for your
list_circle_color
control. Then save. Now refresh your page.You will see your data printed on the page resembling the following:
You see
list_circle_color
set to #AFE039.Now go back and edit your color again, but this time select an Elementor global color. Then save. New refresh your page.
You will see your data printed on the page resembling the following:
Now how to work with this? Recall from above I mentioned that Elementor stores your globals inside
.elementor-kit-N {...}
? Here is a reference at w3schools.But how do you get the value set by
globals/colors?id=13c6ce9
? You can do this using PHP’sstr_replace
, as in the following:This will give you the var with the full property ending that you need, as in:
Now assign either via an internal spreadsheet in your widget, or as an inline style:
Lastly, how do you check to see if you are using a global or a non-globally set color value? Check
__globals__
andlist_circle_color
using a simple if condition:**
$list_circle_color
should be set when you’re specifying your variables. I excluded that before. When you specified$list_circle_color_global
initially above, you would also create$list_circle_color = $settings['list_circle_color'];