1
votes

I am learning WordPress theme development, and I have started to use the following line in my functions.php file.

define( 'MEXICO_THEME_DIR', get_template_directory() );

define( 'MEXICO_THEME_URI', get_template_directory_uri() );

Am I able to use this in the example below in my enqueue-scripts.php file?

wp_enqueue_script( 'popper.js', MEXICO_THEME_URI . '/popper.js' );

Or do I have to create a new "define" name for each PHP page. Is there a method of making this global.

1

1 Answers

0
votes

When you use define('YOUR_CONSTANT', something); what you're doing is generating a constant that can be used by your or anyone else, from everywhere in the site. You could even use the constant defined in a theme from a plugin, and it would still work.

That is why you must ensure that you make them unique to prevent clashes (MEXICO_THEME is unique enough I think), as well as you could also do this, like WooCommerce does

if( ! defined( 'WC_PLUGIN_FILE' ) ){
  define( 'WC_PLUGIN_FILE', __FILE__ );
}