Do you regularly add disclaimers and disclosures to your blog posts for sponsored posts, product reviews or to denote the use of affiliate links? And do you use WordPress?
If you’ve answered yes to the questions above, we’re going to show you how to add turn that disclosure into a reusable shortcode.
What is a shortcode?
According to WordPress, “a shortcode is a WordPress-specific code that lets you do nifty things with very little effort.” Basically, a shortcode is a shortcut.”
Why put my disclosure/disclaimer in a shortcode?
To make life easy, of course! This is a one time job that will save you typing out your disclosure and linking it to your ‘more information’ page each time you run a sponsored piece of content or use an affiliate link. Instead, you’ll simply add the following shortcode into your content:
[disclosure]
That’s much easier to remember, right? For this example, we’re using an disclosure to show readers we use affiliate links on the page. You can customise this easily to output your message of choice – we’ll explain how below.
Instructions:
Open your theme’s functions.php file. Create a backup of the file first and keep it somewhere safe. Then paste in the following code (I usually paste at the bottom of the file).
1 2 3 4 5 6 7 |
//* LOVELYBLOGACADEMY.COM - AFFILIATE DISCLOSURE SHORTCODE function aff_disclosure() { return "<p class='disclosureLBA'>This blog post contains affiliate links. <a href='http://YOURDISCLOSUREPAGE.com'>Learn more</a>.</p>"; } add_shortcode( 'disclosure', 'aff_disclosure' ); |
This registers a new shortcode with WordPress called “disclosure”. When you use the new shortcode it will output your disclosure and a link to your disclosure page.
To start using the shortcode, you’ll add the following snippet at the top of your blog posts:
[disclosure]
Here’s the message it will output:
This blog post contains affiliate links. Learn more.
Want to customise it? No problem…
Customising the disclosure shortcode:
- To edit the wording, change the text between <p class='disclosureLBA'> and </p> (e.g. “This is a sponsored post. Learn more.”).
- Swap "http://YOURDISCLOSUREPAGE.com" for the URL to your site’s disclosure.
- Use p.disclosureLBA to style your disclosure in your CSS stylesheet. Here’s my sample styling, feel free to use:
1 2 3 4 5 6 7 8 9 10 11 12 |
p.disclosureLBA { text-align: center; color: #666; text-transform: uppercase; font-size: 10px; } p.disclosureLBA a { color: #666; text-decoration: underline; } |
This is the end result –
Disclosure: I use referral links in this post, I might make a commission on my recommendations. Learn more.
Simply paste the shortcode [disclosure] into your next blog post. Easy!
ADVANCED
Creating multiple disclosures:
If you run both sponsored posts and affiliate links, you may want to use TWO different shortcodes, each outputting different wording depending on the type of content you’re publishing. That’s easy to do.
Simply add this to the bottom of your functions.php file –
1 2 3 4 5 6 7 |
//* LOVELYBLOGACADEMY.COM - SPONSORED DISCLOSURE SHORTCODE function spon_disclosure() { return "<p class='disclosureLBA'>Sponsored content. <a href='http://YOURDISCLOSUREPAGE.com'>Learn more</a>.</p>"; } add_shortcode( 'sponsored', 'spon_disclosure' ); |
You’ll then use [sponsored] in your content to output the new disclosure.
Once again, customise until you’re happy with the output.
If you need to create MORE disclosures, change the function name spon_disclosure to something of your choosing. Make sure to replace both instances of it in the code. Rename your shortcode (where it says ‘ sponsored ‘ in the last line) to something else too. There’s no limit on how many shortcodes you can add to WordPress, so add as many as you require!
Adding the disclosure into a sidebar widget
You might have noticed that I have my disclosure right at the top of this page, on the right. I’ve added it to my sidebar. If you’d like to do this, you must enable shortcode compatibility for widgets first. It’s really simple. Once again, paste the following code into your functions file –
1 2 3 4 |
//* LOVELYBLOGACADEMY.COM - ENABLE SHORTCODES IN TEXT WIDGETS add_filter('widget_text', 'do_shortcode'); |
Easy peasy. Now head over to Appearance > Widgets
and your shortcode into a text widget. Done!
Helpful? Share this with your friends:
Please tweet this tutorial so we can help other bloggers:
Learn how to turn your blog disclosure into an easy-to-use #WordPress shortcode. Simple! Click To TweetAlternatively, pin the image below:
Thank you!
This was really helpful. I was trying to add multiple disclosures and kept getting stuck. Appreciate the tips.
Hi Grant,
I am pleased the tutorial helped.
Carly.
Awesome post! I just used it to create my disclosure and it was so simple. Thanks!
Very pleased to hear that! Thanks for the feedback 🙂
When I type functions.php, it comes up as ad-funcitons.php. Is this where i stick the code?