How to do auto light/dark mode switching using global variables #168
Replies: 3 comments 3 replies
-
@KevinBatdorf Do you know if this should work as is with the WP Dark Mode plugin? (It does not appear to) https://wordpress.org/plugins/wp-dark-mode/ Maybe, I can add some Code Block Pro Dark Mode CSS changes to this area in the plugin to get it working? |
Beta Was this translation helpful? Give feedback.
-
It would be great if we could pick from the list of existing themes for both light and dark mode. |
Beta Was this translation helpful? Give feedback.
-
I think some CSS variables might be labeled incorrect, is that possible? For example, when using this theme with the CSS variables theme both the functions and variables are treated as functions: add_filter(
'autoblue/share_message',
function ( $message, $post_id ) {
$tags = wp_get_post_tags( $post_id, [ 'fields' => 'names' ] );
if ( ! empty( $tags ) ) {
$tags = array_map( fn( $tag ) => '#' . sanitize_title( $tag ), $tags );
$message .= ' ' . implode( ' ', $tags );
}
return $message;
},
10,
2
); Example when only setting Example when using the One Dark Pro theme. As you can see functions (e.g. |
Beta Was this translation helpful? Give feedback.
-
As a prerequisite, you need to have a theme pack license. You can get one here. This is a paid feature.
After you install and activate it, insert a code block and open the themes panel.
At the top you will see a pretty bland-looking, generic theme. It might look something like this:
Select that theme and save the page.
Next (or do this before if you'd like), you need to add some CSS to your site in order for the styles to show up.
This is a bit verbose, but covers both light and dark modes based on the user's device.
Put this somewhere like functions.php or where is best to put PHP code (leave a comment below or email me if unsure).
You don't necessarily need to set all of these, but it's good to look at your code and tweak it until it looks how you want. It will probably take a bit of trial and error to get it perfect. Also, if you don't care about dark mode, then just remove the bottom half of the code snippet.
Beta Was this translation helpful? Give feedback.
All reactions