Earlier this week we spoke about adding a disclaimer before content with Custom CSS only. This has limits due to different post types and it has no ability to be linked outside of the text you provide.
As the CSS version was being built I was building a code-based version that could be used on all single posts and would give you the ability to add pages to the snippet.
You will need to install the Code Snippets plugin which adds no bloat and allows you to structure and name additions to your site for easier management.
You will want to find the page section and modify it to add any pages you need a disclaimer on, you can use the number or the slug name in single quotes. (The ones on there are examples to replace)
if(is_page( array( 234, 'about-me', 'Contact' ) ) || is_single()) {
Then you can make changes to the CSS below to ensure it displays how you would like it to.
.affiliate {
display: block;
align-content: center;
margin: 5px;
margin-bottom: 5px;
padding-top: 30px;
padding-bottom: 30px;
text-align: center;
font-size: 16px !important;
padding-right: 20px;
padding-left: 20px;
background: #85bb65;
color: #ffffff;
border-radius: 10px;
margin-bottom: 50px;
}
Then you can make changes to the legal disclaimer location if you want to link out. Just replace the below # sign with the website complete URL.
<a href="/disclaimer/">
If you don’t want to link out replace:
<a href="/disclaimer/">disclaimer information</a>
with
disclaimer information
These display on the pages with schema within Acabado also so you have the banner across your recipes, products, etc.
This you can change out page id’s for your resource pages to have a disclaimer (separate each with commas) or use the page name if you enclose like the below in code examples.
Additionally the has_tag code allows you to change to a tag name you want by default it is added to any post with the tag “Affiliate” added to it.
The second line (commented out with a “#” allows you to just have it added to all posts regardless of you tagging it as “affiliate” so choose what works for you.
function wpcontent_before_after($content) {
if(is_page( array( 234, 'about-me', 'Contact' ) ) || is_single() && has_tag('Affiliate')) {
#if(is_page( array( 234, 'about-me', 'Contact' ) ) || is_single() ) {
$beforecontent = '<div class="affiliate"><!--googleoff: index-->As an Amazon Associate we earn from qualifying purchases made on our website. If you make a purchase through links from this website, we may get a small share of the sale from Amazon and other similar affiliate programs. You can read our complete <a href="/disclaimer/">disclaimer information</a> for more details.<!--googleon: index--></div>';
#$aftercontent = '<div class="affiliate">And this will come after, so that you can remind them of something, like following you on Facebook for instance.</div>';
$fullcontent = $beforecontent . $content . $aftercontent;
} else {
$fullcontent = $content;
}
return $fullcontent;
}
add_filter('the_content', 'wpcontent_before_after');
add_action( 'wp_head', function () { ?>
<style>
.affiliate {
display: block;
align-content: center;
margin: 5px;
margin-bottom: 5px;
padding-top: 30px;
padding-bottom: 30px;
text-align: center;
font-size: 16px !important;
padding-right: 20px;
padding-left: 20px;
background: #85bb65;
color: #ffffff;
border-radius: 10px;
margin-bottom: 50px;
}
</style>
<?php } );
You can have a simple bar with a call to action without installing plugins that may make your site insecure, instead build on with code snippets.
Being able to smooth scroll to the top of your website may seem simple but users love it and it is super simple to make and please the visitors!
I get irritated when I link back to my old posts and I get a pingback I have to delete from within comments, this will help you disable them overall.