Referencing a child theme's variable in a parent theme
-
I have a parent theme that is used on about 6 child themes. Each child theme represents a different company.
I’m adding code in my parent theme’s functions.php to insert
<meta property="og:image" content="https://mydomain/mypic.png"/>
into the header so Facebook grabs the right thumbnail. The code is available in several places, but I grabbed it from https://bit.ly/uUuIYZ.The code is working fine when my post has a thumbnail. But the code also allows me to specify a default image so that if a post doesn’t have a thumbnail, it grabs the default image. That’s where my problem is happening.
$default_image="https://example.com/image.jpg";
Instead of specifying a single static image for all child themes, as shown in the code, I want to use a variable from each child theme. So in my Company A child theme’s functions.php, I have added
define ( 'LOGO', '/company_A_Logo.png');
I was hoping to then just use this in the parent theme:
$default_image= $LOGO;
But it’s not working; in my meta tag, it’s generating content=””. I think this is either a basic syntax error or perhaps an issue with the accessibility of the variable. Thoughts?
- The topic ‘Referencing a child theme's variable in a parent theme’ is closed to new replies.