≡ Menu

Insert iFrame Code in Blog Posts- Insert Amazon Products

In one of my blog i was trying to add amazon products in my post manually but  i came to know that wordpress is not accepting iFrame codes in posts. After a few minutes search on google, finally i found that it is possible to insert amazon products or any other iframe codes in a post.

In normal cases when you try to add iframe code in  HTML editor the code disappears as you switch to visual editor. The following are few ways to insert amazon associate affiliate links of a product or any iframe code in a post.
insert iframe code

First Method to insert iFrame Code in Post

The first working method is to paste the iframe code in HTML editor in the location where you want to display it. Make sure to not switch to the Visual Editor and publish the post direct from HTML editor.

It is recommended to paste the iframe code only when you complete the post, in this way you will not need to switch to visual editor.

2nd Method to Insert iFrame Code in Post

This one is the perfect one, because it will help in adding iframe code in every post you want.

Open your function.php file and copy the below code in the file.

unction 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');

Make sure that you add the code before the closing tag ?>

After adding the code in function.php file you will see a new Custom Field in every new post. Now you can paste the iframe code in the field to display in a post.