You can use something like this in your code injection footer:
<style>
.global-alert {
padding: 1.5rem 0;
background: rgba(0 0 0 / 0.15);
text-align: center;
margin-top: 3.5rem;
}
</style>
<script>
const globalAlert = document.createElement('div');
// If you need to insert markup, use this line:
globalAlert.innerHTML = '<strong>Announcement</strong>: Something to announce'
// If you only need to insert text, use this line:
globalAlert.textContent = 'We independently review everything we recommend. When you buy through our links, we may earn a commission.';
globalAlert.classList.add('gh-inner', 'global-alert');
document.getElementById('gh-head').appendChild(globalAlert);
</script>
Note that you might need to tweak this behavior if your post has a cover image.
To make it look like a callout card, you can modify the second to last line of the script.
before: globalAlert.classList.add('gh-inner', 'global-alert');
after: globalAlert.classList.add('gh-inner', 'global-alert', 'kg-card', 'kg-callout-card', 'kg-callout-card-grey'); (you can change grey to any of the supported colors)
You might need to modify your theme to make that happen (if you’re using internal tags), since I don’t think there’s a way to check if a post has a specific internal tag without making a theme change
I now have this working below my header as per the original code you provided but when I set a post template to full feature the global alert appears on top of the image as it all becomes the header.
Any suggestions on how to get around this? Thanks in advance
Hey - I have actually settled for leaving a disclaimer in the body of the post/page and I am able to target only posts with affiliate links by using the following code: