How to Create a Text Block ShortCode for Content You Repeat in WordPress

Tweet about this on TwitterShare on Google+Pin on PinterestShare on FacebookShare on LinkedInShare on RedditBuffer this pagePrint this page

Faster Blogging How to TipsDo you have content on your blog that you repeat often?  Maybe it is your affiliate disclaimer or maybe it is your closing statement.

Do you ever wish there was a fast way to add the content to your site without a bunch of cutting and pasting?

There is!

Today, I’ll show you how.

Example of a Text ShortCode

A short code is a small amount of text that tells your site to perform some kind of programming code.  In today’s example, it will insert a longer string of text.

Example #1 – Closing Statement on Post

When I write my blog posts, I sign off each blog in the same way.

Live Fully -- Love Openly -- Laugh Often -- Leverage Your Brilliance -- Connect Authentically -- Get Your Message Out -- Serve with Impact -- Prosper Everyday

Steph Calahan



IF YOU LIKE THIS POST AND THINK IT WOULD BE VALUABLE TO YOUR COMMUNITY, PLEASE SHARE IT!

However, that is not what I type!  At the end of each post, I simply type

[close]

 

Example #2 – Affiliate Disclaimer

It is required by law to notify your readers when you have used affiliate links in any of your online work.  That includes your blog posts.  I wanted to make sure that my statements were consistent through my site AND easily changeable if the FTC updates their policies.

When I have affiliate links in my posts, you will see

Disclosure: Some of the links on this page are affiliate links. That means that I may get a small thank you commission (at no additional cost to you) if you choose to purchase a product from the company mentioned. I only refer you to programs that are ran by people I personally know or I have participated in, but please use your judgement to decide if this is right for you. If you would prefer that I not get that, feel free to Google the company and purchase directly.

To get that text along with the formatting, I simply type

[affiliate]

Cool right?

 

How to Make the Text Shortcodes

Shortcodes are created by modifying your Functions PHP file in WordPress.  I have shared the code snippits below that allow me to have the two shortcodes I mention in my examples.  Feel free to give this to your webmaster or add it to your Functions PHP file if you are comfortable modifying code.  Remember: Make sure to make a backup before changing any code! 

The blue box below shows you the PHP code necessary to create a [close] shortcode.  Change the text in red to reflect the text that you want displayed in your content.

//** ADD SHORTCODES BLOG CLOSE STATEMENT    */

function BlogClosingShortcode() {
return ‘<em><p>PUT THE TEXT THAT YOU WANT TO USE HERE</p></em>';
}
add_shortcode(‘close’, ‘BlogClosingShortcode’);

 

The blue box below shows you the PHP code necessary to create a [affiliate] shortcode.  Change the text in red to reflect the text that you want displayed in your content.

//** ADD SHORTCODES AFFILIATE STATEMENT    */

function AffiliateShortcode() {
return ‘<p><span style=”font-size: small; color: #808080;”>Note: Some of the links in this post are affiliate links.  That means that I may get a small thank you commission if you choose to purchase a product from the company mentioned.  I only refer you to programs that are ran by people I personally know or I have participated in, but please use your judgement to decide if this is right for you. If you would prefer that I not get that, feel free to Google the company and purchase directly.  No matter how you decide, I would rather you have tools that work for your business.</span></p>';
}
add_shortcode(‘affiliate’, ‘AffiliateShortcode’);

 

That’s it!

As we were building this site the geek in me went into a bit of overdrive.  We found and logged a number of tools and tricks to help us work faster and communicate better.  I don’t normally share stuff this techie in my posts.

If you are interested in seeing more tips like this, please mention it in the comments.  

Tweet about this on TwitterShare on Google+Pin on PinterestShare on FacebookShare on LinkedInShare on RedditBuffer this pagePrint this page

Comments

  1. says

    Beats the cut and paste that I use for my blog sign offs! Must discuss it with my techie team the next time we upgrade the website. I managed a favicon all on my own last week but this one will require some assistance. Thanks Stephanie for the tip.

  2. says

    This is so helpful! What I really need is to make the content a link, as I find I often need to include a link to my post “How to create a free google account, send me a private message on Google+, and get into my Hangouts.”

    As you can see, that’s a lot of repeat typing, then making it a link too is time consuming. Is there a way to make the shortcode sentence a link? Would love to use the code to type out that sentence and make it a link to its corresponding blog post.

    Great tip, thanks Stephanie!

    • says

      There is absolutely a way to do that! You can replace from including

      to the

      and replace it with the code for a text link.

      Here is a fast way to get that code:

      Go to your WP editor and create a new page with your text link like you normally would.

      Then, look in the “text” tab where you see all of the HTML code.

      Copy

      Replace what you’ve copied.

  3. says

    Stephanie, I could spend hours and hours and hours on your site. I’m glad you posted this message. It may be techie but being a non techie – I needed the information! Now, perhaps I’ll try this and not be so intimidated:-) Thank you!

  4. says

    Brilliant! I just started putting the same ending on all my posts (inviting folks to sign up for the newsletter) and this will save me a ton of time. Off to find that PHP file.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>