Help resolve "Use of undefined constant" in Theme?


Hi there,

Just checking my theme in WP_DEBUG mode for errors and got a few “Use of undefined constants” even though the theme works perfectly.

The errors are in a function that uses the “wp_enqueue_scripts” and ive used a few if statements to check if the current post/page used certain meta fields. I’m using the WP Alchemy class for my custom fields though i think this isn’t the problem…

function theme_scripts() {
	global $post, $pixelstore_mb_product;
	$productmeta = get_post_meta(get_the_ID(), $pixelstore_mb_product->get_the_id(), TRUE);	
	if (!is_admin()) {		
		if ($productmeta[productgallery] == "Hover Zoom") {
			wp_enqueue_script( 'etalage', $script_folder . 'jquery.etalage.min.js', 'jquery');
add_action('wp_enqueue_scripts', 'theme_scripts');

and the WP_DEBUG shows the following:

Notice: Use of undefined constant productgallery - assumed 'productgallery' in /Users/MattStrange/Sites/pixelstores/wp-content/themes/theme/includes/theme_scripts.php on line 20

Notice: Uninitialized string offset: 0 in /Users/MattStrange/Sites/pixelstores/wp-content/themes/theme/includes/theme_scripts.php on line 20

Any help mucha appreciated.



change $productmeta[productgallery] to correct $productmeta[‘productgallery’]

dtbaker said

change $productmeta[productgallery] to correct $productmeta[‘productgallery’]

Thank dtbaker, can’t believe it was that simple, that worked like a charm!

One more thing now the errors displays:

 Uninitialized string offset: 0 in /Users/MattStrange/Sites/pixelstores/wp-content/themes/theme/includes/theme_scripts.php on line 20

Any ideas?


Change this:

if ($productmeta['productgallery'] == "Hover Zoom") {

to this:

if (isset($productmeta['productgallery']) && $productmeta['productgallery'] == "Hover Zoom") {


AH! Thanks guys for the help, all good now :slight_smile: