Insert iFrame Code in Blog Posts- Insert Amazon Products

Updated October 6, 2023

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.


  • Cristian

    Hi, I’ve tried your method, but didn’t run on BLOGGER.
    Can you find a solution?
    If I choose HTML and paste the Iframe code and then I publish it, I have a blank post….

  • damtachoa

    I did use the first method, but the amazon banner not showing at all. What can I do? Please help.

  • I am trying to add multiple iframe in a post, but it only shows one iframe, it is not showing anything after that iframe code including just plain texts. Is there a way to fix this?

  • Mark Levsky

    i was trying to insert amazon iframe in a blog i created new page and inserted code but can see only half a shop can display all ,does anyone knows how i can fix this?

    • Bilal Ahmad

      Mark@ Paste the Amazon code in HTML Editor and click the “Publish” button. Don’t revert to Compose Mode otherwise it will not work.

Leave your comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.