File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,38 @@ function usesBlockTheme() {
44 return ! ! document . querySelector ( 'div.wp-site-blocks' ) ;
55}
66
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+
739// Detects if a WordPress embed block is on the page
840function hasWordPressEmbedBlock ( ) {
941 return ! ! document . querySelector ( 'figure.wp-block-embed' ) ;
@@ -195,6 +227,7 @@ function usesInteractivityAPI() {
195227}
196228
197229const wordpress = {
230+ theme : getWordPressTheme ( ) ,
198231 block_theme : usesBlockTheme ( ) ,
199232 has_embed_block : hasWordPressEmbedBlock ( ) ,
200233 embed_block_count : getWordPressEmbedBlockCounts ( ) ,
You can’t perform that action at this time.
0 commit comments