Daily Code: Day 2 – Show Me…. Bananas!

Daily Code: Day 2 – Show Me…. Bananas!

Daily Code: Day 2 – Show Me…. Bananas!

Going Bananas for Day 2 of Daily Code!

Simple WordPress Shortcode

Here is a quick one for today. A custom WordPress shortcode to display an inline image. In this case….. BANANAS!

This is something I wanted to have on KingKode for whenever I wanted to use it. Like right here [bananas].

All lines below are added at the very bottom of functions.php.

Callback Function:
function show_me_bananas() {
   $image = "<img class='bananas' src='/images/banana-icon.png'/>";
   return $image;
}

First, we need a function that spits out the image markup. The above sets the img markup as variable $image. Then returns the variable string when fired.

Register Shortcode Function:
function register_new_shortcodes(){
   add_shortcode('bananas', 'show_me_bananas');
}

Then, we need to link the previous function to a shortcode. add_shortcode() registers the show_me_bananas() function to the shortcode [bananas]. Note: you can register many other shortcodes with this function.

Hook into WordPress:
add_action( 'init', 'register_new_shortcodes');

Finally, WordPress needs to know that we have a new shortcode. add_action() gets fired when the page is initializing. register_new_shortcodes() is then added to the initialization process and, thus, your shortcodes have been registered.

Oh, yeah… The CSS:
.bananas {
display: inline-block;
margin: 0px 2px;
}

The CSS can be put at the very bottom of stylesheet.css. display: inline-block tells the image to be treated like a block element while inline with the text. margin: 0px 2px adds spacing on either side of the bananas for kerning purposes.

And now we have bananas! [bananas][bananas][bananas][bananas][bananas][bananas][bananas]



Join the Conversation

Loading Facebook Comments ...

77 thoughts on “Daily Code: Day 2 – Show Me…. Bananas!

  1. AvatarBeauty

    Wow, marvelous weblog structure! How long have you been blogging for?
    you make blogging look easy. The whole glance of your
    web site is fantastic, as neatly as the content material!

  2. Avatarsocial media

    First of all I want to say awesome blog! I had a quick
    question which I’d like to ask if you don’t mind. I was interested to know how you center yourself and clear your mind prior to writing.

    I have had a hard time clearing my thoughts in getting my ideas out.
    I truly do enjoy writing but it just seems like the first 10 to 15 minutes tend
    to be wasted just trying to figure out how to begin. Any recommendations or hints?

    Cheers!

  3. AvatarCecila

    I’m amazed, I have to admit. Rarely do I come across a blog that’s both equally educative and amusing, and let me tell
    you, you have hit the nail on the head. The issue is something that not enough folks are speaking intelligently about.

    I am very happy that I stumbled across this during my search for something relating to this.

  4. Avatarfriendly mutton chops beard

    Hello I am so thrilled I found your weblog, I really found you by accident, while I was
    researching on Bing for something else, Anyways I am here now and would just like to say thanks a lot
    for a remarkable post and a all round thrilling blog (I also love the theme/design), I don’t have time to browse it all at the
    moment but I have book-marked it and also included your RSS feeds, so when I have time I will be back to read more, Please do keep up the superb job.

  5. AvatarVonnie

    It is really a great and useful piece of info.
    I’m glad that you just shared this helpful information with
    us. Please keep us up to date like this. Thank you for sharing.

  6. Avatarreal vs fake art acnl

    Hey I am so delighted I found your web site, I really
    found you by mistake, while I was researching on Aol for something else, Regardless I am here now and would just
    like to say cheers for a remarkable post and
    a all round exciting blog (I also love the theme/design), I don’t have
    time to look over it all at the moment but I have book-marked it and also added your RSS feeds,
    so when I have time I will be back to read a great deal more, Please do keep up
    the great job.

  7. Avatarbuy instagram followers

    May I simply just say what a comfort to discover somebody that actually
    understands what they are discussing over the
    internet. You definitely know how to bring a problem to light and
    make it important. More people must read this and understand this side of your story.
    I can’t believe you’re not more popular given that you certainly possess the gift.

  8. AvatarReceive News

    Hey there! Do you know if they make any plugins to help with SEO?
    I’m trying to get my blog to rank for some targeted keywords
    but I’m not seeing very good success. If you know of any please
    share. Thank you!

  9. Avatarall4webs.com

    Subsequent section the place you have got most likely
    heard of after which lock up the full worth of. It then starts to with a couple of consecutive tumbles earlier than stabilizing around its current value.
    Wifi networks have gained so much cash the worth of bitcoins vs the US.
    Each cryptocurrency comes wrapped Bitcoin WBTC minted in August Distx have been. Moreover the
    brokers exist to assist you’ve gotten that consciousness in you’ll.
    Coindesk columnist Nic Carter is companion at Castle Island
    Ventures a public cryptocurrency deal with. The risk of loss it’s best to learn about buying Bitcoin is a public book.
    Bitcoin what are susceptible to elevated means of transportation the state of cryptocurrency.

    Thoughts and opinions are recorded is what’s cryptocurrency how does it let you know.
    Decoding of cryptocurrency you have to be rising lively and
    chosen traders from the mainstream financial institutions.

    Serving to you out discover out along many of the hurdles
    many traders fall down. Finder is committed to helping many individuals all around the internet or information stations over the previous.

  10. Avatarspboqq

    hey there and thank you for your info – I have definitely picked up something
    new from right here. I did however expertise a few technical issues using this website, as I experienced to
    reload the web site lots of times previous to I could get it to load properly.
    I had been wondering if your hosting is OK? Not that
    I’m complaining, but slow loading instances times will often affect your placement in google and can damage your high quality score if advertising and marketing with Adwords.
    Well I’m adding this RSS to my e-mail and can look out for a lot more of your
    respective fascinating content. Make sure you update this again very
    soon.

  11. AvatarRoad bike

    Magnificent goods from you, man. I’ve understand your stuff
    previous to and you are just too fantastic. I really like what you have
    acquired here, really like what you’re stating and the
    way in which you say it. You make it enjoyable and you still care for to keep it sensible.
    I cant wait to read much more from you. This is really a
    terrific site.

  12. Avatarmp3juices

    My brother suggested I would possibly like this blog.
    He was totally right. This post truly made my day.

    You can not imagine just how so much time I had spent for this information! Thanks!

  13. Avatargay porn

    My spouse and I stumbled over here different web address and thought I should check things out.
    I like what I see so i am just following you. Look
    forward to checking out your web page for a second time.

  14. Avatar多产

    Whats up this is kinda of off topic but I was
    wanting to know if blogs use WYSIWYG editors or if you have to manually code
    with HTML. I’m starting a blog soon but have no coding skills
    so I wanted to get advice from someone with experience.
    Any help would be enormously appreciated!

  15. AvatarApilimod

    you are in point of fact a just right webmaster. The website loading velocity is incredible.
    It sort of feels that you are doing any unique trick. Furthermore, The contents are masterwork.
    you have done a excellent process on this subject!

  16. Avatarchelsea fc jerseys

    When I initially left a comment I seem to have clicked the -Notify
    me when new comments are added- checkbox and from
    now on every time a comment is added I recieve four emails with the same
    comment. There has to be an easy method you are able to remove me from that service?
    Kudos!

  17. AvatarUnblocked

    This is very interesting, You are a very skilled
    blogger. I have joined your rss feed and look forward
    to seeking more of your wonderful post. Also, I have shared your site in my
    social networks!

  18. Avatarmovie

    Hmm is anyone else having problems with the images
    on this blog loading? I’m trying to figure out if
    its a problem on my end or if it’s the blog. Any responses would be greatly appreciated.

  19. Avatarphotos,

    What i do not understood is actually how you’re not really a lot
    more smartly-appreciated than you may be now. You are so intelligent.
    You understand thus considerably relating to this subject,
    produced me for my part consider it from so many varied angles.
    Its like men and women don’t seem to be fascinated unless it is one thing to accomplish with Lady gaga!
    Your own stuffs great. Always deal with it up!

  20. AvatarINDIAN Visa

    With havin so much content do you ever run into any issues of
    plagorism or copyright infringement? My site has a lot of completely
    unique content I’ve either created myself or outsourced
    but it appears a lot of it is popping it up all over
    the internet without my agreement. Do you know any techniques to help prevent content from being
    stolen? I’d really appreciate it.

  21. Avatartv task management

    After I originally commented I seem to have clicked on the -Notify me when new comments are added- checkbox and now whenever a comment is
    added I receive four emails with the same comment.

    Perhaps there is a way you can remove me from that
    service? Thanks a lot!

  22. AvatarPlay8oy apk ios

    Hey There. I found your blog using msn. This is an extremely smartly written article.
    I’ll be sure to bookmark it and return to read
    extra of your useful information. Thanks for the post.
    I’ll certainly comeback.

  23. Avatarplay8oy test id

    There are a selection of online casino sites available,
    however, some are fake pictures. Are there any hidden conditions that I needs to know
    about before I register with this free movie blog?

  24. Avatar918kiss review

    Plain pastel backgrounds work well and include soft touches like baby feathers
    and tiny beads. If a website is on web since a number of years
    then it gets authority. Kim lives in Southern Indiana with
    her husband Gary, a reverend.

  25. Avatarocean king rig

    Acting as a guest blogger allows writer to create relevant backlinks to incredibly blogs.
    As you can imagine, fairly slow process. My time iis tooo precious down the
    sinnk on fledgling sites.

Leave a Reply to live dealer blackjack golden nugget Cancel reply

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

three × one =