Conditional PHP in Header Ad box

Posted in: Newspaper
Post count: 18

Good day,

I’d like to use some PHP code in the header ad’s space. This was previously working until I updated the theme and likely reset some coding I did.

The site is https://moarcookies.com

The code is using the plugin Twitch Conditional and the code I’ve previously used was:
<?php if (twitch_is_live('moarcookies')) { ?>
<div align="center" style="background-color:#c1711b; color:#fff; padding-left:10px; padding-right:10px;">We’re Live! Come join in the conversation and click on the Twitch icon in the lower right of the stream!</div><br /><div id="twitch-embed"></div>

<script src="https://embed.twitch.tv/embed/v1.js"></script>

<script type="text/javascript">
new Twitch.Embed("twitch-embed", {
width: "100%",
height: 480,
channel: "moarcookies",
allowfullscreen: true,
});
</script>
<?php } else { ?>
<?php } ?>

This would set it to only show up when the stream is live, and disappear when we’re not live. I’ve tried using the code in parts>header>ads.php but it didn’t work at all. Is there somewhere else I can place it so that it looks the same as it does right now?

Post count: 20688

Hi,

Code entered in the theme panel will be saved in the database, so updating the theme will not affect it in any way.

Maybe double check your code and make tests, it should work same as before
https://www.mitchcanter.com/twitch-conditional-plugin/
https://github.com/thatmitchcanter/twitch-conditional

Try to enter the code in the header template directly, where the ad should appear. Multi-purpose header styles are in the composer plugin so you would have to enter the code there
https://www.screencast.com/t/wLznd0aIWpl
These modifications will be lost when the theme/plugin is updated however. That will be the case for the parts/ads file, unless you modify this one in a child theme.

Thanks

Post count: 18

Thanks. This worked. I just needed to add a space into the header ad box to enable it once the code was in the header.

Viewing 3 posts - 1 through 3 (of 3 total)
The forum ‘Newspaper’ is closed to new topics and replies.