VividVisions

by Walter Krivanek

Articles of with the tag “custom”

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.

Creative Commons icons as custom shapes for Photoshop

Creative Commons icons as custom shapes for Photoshop

If you want to mark your design work as licenced under a Creative Commons licence and include the respective icons, you can download them as SVG, EPS and PNG files and even as true type font at creativecommons.org/about/downloads/. Since I often work with custom shapes in Photoshop, I created a custom shape set featuring all Creative Commons icons, which I wanted to share with you. Download it here.

What are Creative Commons licences?

Creative Commons licences are the right choice if you want to share your work with others. For instance: the contents of this website are generally licenced under the Creative Commons BY-NC-ND 3.0 licence, which means that you can use the texts and images I created for non-commercial purposes without asking me, provided that you don’t change them and credit me, ideally with a link to this website.

Creating this set was only possible, because the icons themselves are licenced under the Creative Commons Attribution Licence, which allows me to adapt and share them.

To learn more, watch the videos below and visit creativecommons.org/about/.


(via helge.at)