Skip to content

Instantly share code, notes, and snippets.

@19h47
Last active May 5, 2023 15:41
Show Gist options
  • Save 19h47/806c10bd977aa63929dd14e2035e9d28 to your computer and use it in GitHub Desktop.
Save 19h47/806c10bd977aa63929dd14e2035e9d28 to your computer and use it in GitHub Desktop.
WP Get Theme
<?php
/**
* Plugin Name: WP Get Theme
* Plugin URI: https://gist.github.com/19h47/806c10bd977aa63929dd14e2035e9d28
* Description: Get various information from current theme thanks to WP_Theme object.
* Version: 0.0.3
* Author: Jérémy Levron
* Author URI: https://19h47.fr
*
* @package 19h47/wp-get-theme
*/
if ( ! function_exists( 'get_theme_manifest' ) ) {
/**
* Get theme manifest
*
* Get theme manifest create by webpack-manifest-plugin
*
* @see https://github.com/shellscape/webpack-manifest-plugin
* @since 0.0.0
* @return bool|array
*/
function get_theme_manifest() {
$file = get_template_directory() . '/dist/manifest.json';
return json_decode( file_get_contents( $file ), true ); // phpcs:ignore
}
}
if ( ! function_exists( 'get_theme_version' ) && function_exists( 'wp_get_theme' ) ) {
/**
* Get the theme version.
*
* @since 0.0.0
* @see https://developer.wordpress.org/reference/functions/wp_get_theme/
* @return string The version number of the theme.
*/
function get_theme_version() : string {
return wp_get_theme()->Version;
}
}
if ( ! function_exists( 'get_theme_name' ) && function_exists( 'wp_get_theme' ) ) {
/**
* Get the name of the theme.
*
* @since 0.0.0
* @see https://developer.wordpress.org/reference/functions/wp_get_theme/
* @return string The name of the theme.
*/
function get_theme_name() : string {
return wp_get_theme()->Name;
}
}
if ( ! function_exists( 'get_theme_icon' ) ) {
/**
* Get icons of the theme
*
* @param string $icon The icon name.
* @param array $args Args.
*
* @since 0.0.0
* @return void
*/
function get_theme_icon( string $icon, array $args = array() ) : void {
$template = 'svg/use.html.twig';
$data = $args;
$data['icon'] = $icon;
Timber::render( $template, $data );
}
}
if ( ! function_exists( 'get_theme_text_domain' ) && function_exists( 'wp_get_theme' ) ) {
/**
* Get the text domain used in the theme for translation purposes.
*
* @since 0.0.0
* @return string The text domain.
* @see https://developer.wordpress.org/reference/functions/wp_get_theme/
*/
function get_theme_text_domain() : string {
return str_replace( '-', '', sanitize_title( wp_get_theme()->get( 'TextDomain' ) ) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment