Code snippets are sometimes a non-optional pathway for WordPress users.
While there are lots of plugins, often times it’s best to use a code snippet to keep the blog running smooth.
However, I’ve always hesitated to include code snippets in my posts because I didn’t want to run a plugin to ensure that the code would stay free a stray characters.
While one can just type out the code, stray code is going to pick up formatting and character conversion if one is not super-duper careful.
Many blogs use a plugin to handle code, such as WP Syntax Highlighter.
Frankly though, with as few posts as I write that require code, the idea of using a plugin was a no-go. On a big active site like mine, plugins are resource use, and resource use is a precious commodity on a hosting plan. There was just no way to squeeze one in.
So I usually found myself avoiding including code if it wasn’t absolutely necessary.
Today, I was again looking for an option and this time I was approaching it from a “maybe I can embed this” idea.
First I stumbled on Embedly, which works with PasteBin, but the embed was not behaving nicely at all.
First, log into PasteBin and create an account. You’ll want to have a real account vs working anonymous. This way you have easy access to locate these code blocks in the future.
Once you have an account, made a new paste. Give it a HELPFUL or RELEVANT name and click Submit.
On the next page, near the top, you will find a link to get to the embed options page.
Once you click on that, you’re taking to a page that offers you two different embed code variations. I personally like the iFrame one.
Copy and paste the iframe embed code (everything in pale yellow) and then use this embed code in your blog the same way you embed a native YouTube iframe (by pasting it into your TEXT side of your post editor).
Once you’ve done that, save the post draft, and preview, and it will look like this (with your own code of course):
On WordPress visual editor, you can slightly drag and scale the preview box, to get it as tall or short as you want it to be.
And if you ever need to locate these snippets, they are all stored nicely in your PasteBin profile which you can find by logging in and then clicking either on your ID or on “my PasteBin”.
PasteBin is a site that has been around a long while and is well trusted in the tech community. I don’t anticipate them to be leaving any time soon, so I’m comfortable using them.
I’m really happy with this option and now I can include more unformatted codeblocks without having to use a plugin. Yay!
~ Kim ~
Simple Tech Tips For Marketing
PS: Never ever go through someone else’s pastebins and randomly apply their code to your site. Many of us use pastebin to share broken, problematic, unstable code that we are troubleshooting with our colleagues. That could be a fast way to break your site!