Adding JavaScript or iFrames to your WordPress posts

Have you ever been posting away on your blog or adding new pages to your website and have noticed that when you switch from the “HTML” to “Visual” page you lose some of your code? It seems that WordPress gets rid of your Javascript, iFrames and some of your other HTML during the switch. I’m running the latest version of WordPress (3.3.2) and this bug still hasn’t been fixed.

I came across an excellent fix to this problem and I wanted to share it with you!

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

// DISPLAYING CUSTOM FIELDS IN POSTS VIA [field name=$var]

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 may use short codes in your content to call custom fields. Use this shortcode: [field name=(custom field name here)]
You’ll need at least WordPress 2.5 to be able to use shortcodes.

A Big Thanks to Walter Krivanek at Vivid Visions!


Posted: May 14, 2012 - Blog

Our WorkJust a few of our favorites.

Dr. Diane Ozog & Associates

Custom Wordpress Web Design

Custom Wordpress Web Design, Logo Design.

WSEA Tutoring

Marketing Services and Branding

WSEA Tutoring, Responsive Wordpress Web Design, Online Marketing Services, Logo & Branding Design and Print Design

Mansion Hill Inn

Responsive Wordpress Web Design

Wordpress Web Design, Boutique Hotel, Responsive Web Design