This snippet defines a reusable custom theme constant for the active WordPress theme directory URL. It helps developers access the theme path globally throughout the theme or plugin files without repeatedly calling WordPress functions.
/**
* Define custom theme constants.
*
* This snippet creates a reusable constant for the active
* theme directory URI, allowing easier access to theme assets
* such as CSS, JavaScript, images, and other files.
*
* Defined Constant:
* - THEME_PATH
*/
function sj_define_theme_constants() {
// Prevent constant redefinition.
if ( ! defined( 'THEME_PATH' ) ) {
define( 'THEME_PATH', get_template_directory_uri() );
}
}
add_action( 'init', 'sj_define_theme_constants' );