In Genesis Facebook group a user asks:
Hi everyone I’m wondering which genesis hook are would be best for a blanket affiliate links disclosure across by blog posts on my blog. They need to be at the top for Australia but I don’t want them being in my excerpts.
We can add custom HTML content above the content using the genesis_before_entry_content
action hook and restrict it to single Posts using an if conditional.
Step 1
Add the following in child theme’s functions.php:
add_action( 'genesis_before_entry_content', 'custom_affiliate_disclosure' );
/**
* Add custom affiliate link disclosure notice above the content on single Posts.
*/
function custom_affiliate_disclosure() {
// if this is not a single Post, abort.
if ( ! is_singular( 'post' ) ) {
return;
} ?>
<div class="affiliate-disclosure-notice">
<p>This post may contain affiliate links. <a href="#">Click here</a> to find out more about this.</p>
</div>
<?php }
Change the HTML to your desired content.
Step 2
Add the following in child theme’s style.css:
.affiliate-disclosure-notice {
margin-bottom: 30px;
padding: 12px;
border: 1px solid #e2e2e2;
background-color: #eee;
font-size: 16px;
font-style: italic;
text-align: center;
}
.affiliate-disclosure-notice p:last-child {
margin-bottom: 0;
}
Thanks Sridhar for the code. I was thinking about to add a Affiliate disclosure notice system and you made the way to do. Just saved my time. Thanks bro.
Wow thank you!.
Is it possible to remove this from posts in one category alone?
Thanks.
Yes.
Try adding this in functions.php instead:
Replace
category-slug
with the slug of your category.Thank you very much.
Sridhar – you’ve given updated code for excluding a specific category – what would I do it have it apply to one category only. I keep messing up my conditional coding…
Try this:
Replace
category-slug
with the slug of your category.I’ve copied both steps into my function.php and style.css. The disclosure shows in my post, but the text style hasn’t changed. Any idea why this would be?