VividVisions

by Walter Krivanek

Articles of with the tag “post”

WordPress: Add iframes to your post using custom fields and shortcodes

The visual editor of WordPress (TinyMCE) loooves to remove iframes from the content. This can be extremely annoying when you want to add Google Maps or other iframe-based widgets to your post. There are several approaches to a solution:

  • Turn off the visual editor
    No problem for someone who has a good grasp of HTML. Not quite a solution, more of a workaround.
  • Edit the TinyMCE configuration files
    The required changes are simple but could be lost with the next update of the editor.
  • Use plugins
    I’m sure, there are tons of WordPress plugins which address exactly this issue but more plugins also mean more maintenance. Especially, when there is a much simpler solution.

Add the following code to the functions.php file of your theme:

function field_func($atts) {
   global $post;
   $name = $atts['name'];
   if (empty($name)) return;

   return get_post_meta($post->ID, $name, true);
}

add_shortcode('field', 'field_func');

Now you can display the value of a custom field in your post by adding the shortcode [field name=name-of-your-custom-field] to your content at the position where you would like it to be shown. Just make sure that the shortcode stands alone on a line, otherwise WordPress would wrap it in a paragraph, which would result in invalid HTML.

To add an iframe, simply paste the HTML code into the ”value” area of your custom field, like shown here:

Wordpress field function

Voilá. Your iframe (or any other HTML code for that matter) will not be removed from your post and you can edit the code without having to switch to the HTML mode.

Update: You’ll need at least WordPress 2.5 to be able to use shortcodes.

Dialogue of the Week (Arianna Huffington and Jon Stewart)

On December 3rd Arianna Huffington, co-founder of the well known Huffington Post, appeared on The Daily Show with Jon Stewart to promote the new book ”The Huffington Post Complete Guide to BloggingAmazon”. She was trying to explain the fascination of blogging to Jon Stewart when this great dialogue occurred:

Arianna Huffington: ”You know, 50.000 blogs are started every day.”

Jon Stewart: ”You make it sound like a sexually transmitted disease.”

Arianna Huffington: ”No, it’s a lot more fun.”

Watch the full episode of The Daily Show here.

The Daily Show with Jon Stewart

Do you speak English?

I decided to write some of my future articles in English and therefore I’m currently translating the pages of this website (but not the old articles – after all, I’ve got work to do :-) ). I’m doing this for two reasons:

First of all, I’ve grossly neglected this blog lately and I wanted to change that. So, if I am going to devote more time to it anyway, why not write in English to reach a broader, more international audience while I’m at it?

Secondly, my English got a bit rusty over time. And when I say “a bit”, I really mean that I’ve been sitting on this post forever using five different online dictionaries and Google to find the right phrases. Yes, it is that bad. ;-) But reading the original English version of “The Gun Seller”, a great, fun novel written by Hugh Laurie, whetted my appetite for this language and I thought my website would be a great playground to train and improve my active vocabulary.

Color or colour?

Since I am European, British English seems to be the natural choice for my blog but coming from a programming background, the word “colour” just looks misspelt to me. So I guess, I’ll stick to the seemingly established tradition among bloggers, whose first language isn’t English, to randomly mix British English and American English with a pinch of the mother-tongue’s Grammar. Feel free to correct my spelling and/or grammar wherever you feel necessary. ;-)