File tree 1 file changed +33
-0
lines changed
1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,38 @@ function usesBlockTheme() {
4
4
return ! ! document . querySelector ( 'div.wp-site-blocks' ) ;
5
5
}
6
6
7
+ /**
8
+ * Detects the WordPress parent and child theme slugs.
9
+ *
10
+ * See https://core.trac.wordpress.org/changeset/59698.
11
+ *
12
+ * @returns {object } Object with fields `theme` and `parent_theme`.
13
+ */
14
+ function getWordPressTheme ( ) {
15
+ const theme = {
16
+ theme : null ,
17
+ child_theme : null ,
18
+ } ;
19
+ try {
20
+ const bodyClass = document . body . classList ;
21
+
22
+ const parentTheme = Array . from ( bodyClass ) . find ( c => c . startsWith ( 'wp-theme-' ) ) ;
23
+
24
+ if ( parentTheme ) {
25
+ theme . theme = parentTheme . replace ( 'wp-theme-' , '' ) ;
26
+ theme . child_theme = '' ;
27
+ }
28
+
29
+ const childTheme = Array . from ( bodyClass ) . find ( c => c . startsWith ( 'wp-child-theme-' ) ) ;
30
+
31
+ if ( childTheme ) {
32
+ theme . child_theme = childTheme . replace ( 'wp-child-theme-' , '' ) ;
33
+ }
34
+
35
+ } catch ( e ) { }
36
+ return theme ;
37
+ }
38
+
7
39
// Detects if a WordPress embed block is on the page
8
40
function hasWordPressEmbedBlock ( ) {
9
41
return ! ! document . querySelector ( 'figure.wp-block-embed' ) ;
@@ -195,6 +227,7 @@ function usesInteractivityAPI() {
195
227
}
196
228
197
229
const wordpress = {
230
+ theme : getWordPressTheme ( ) ,
198
231
block_theme : usesBlockTheme ( ) ,
199
232
has_embed_block : hasWordPressEmbedBlock ( ) ,
200
233
embed_block_count : getWordPressEmbedBlockCounts ( ) ,
You can’t perform that action at this time.
0 commit comments