I would like to load a WordPress post into an iframe when a link on a WordPress page is clicked. This is the link I currently have.

<a href="' . get_post_permalink($sight->ID) . '" target="map-loader">Read the report</a>

Then I want the content of that post (no header or footer etc) to load into an iframe when the link is clicked. This is the iframe that is on the page.

<iframe name="map-loader" src="https://wordpress.stackexchange.com/questions/131143/map-iframe.php"></iframe>

I am half way there. When the link is clicked, the iframe loads a full wordpress page with the header and footer etc. what I want is the actual post content to be loaded into the iframe, no header or footer.

I have tried this in map-iframe.php but no success. Still loads the whole wordpress template.

<?php the_content('Read the rest of this entry »'); ?>

I’m thinking that my link needs something that specifies that I only want to load the post content.

Or would it be better to load with ajax?

1 Answer
1

Not sure, but I think ajax solution would be more apropriate.

But anyways, if I understand this corectly, you have an archive where full posts are loaded inside iframe.

If this is a case you can modify template file (single.php) and remove header and footer

take a look at Template Hierarchy

for further reading I found this which will guide you to more advanced features:http://bavotasan.com/2009/custom-template-for-single-posts-in-wordpress/

Note: if you also want to get rid of adminbar, try this: show_admin_bar(false); at the top of your code.

Have not tested but if this does not work, you can hook inside init
and check

if(is_page()) {
    show_admin_bar(false);
}

Edit:

You can also setup a new page which will get post depending on ID.

First lets create custom-template

  • In your themes folder create file template-iframe.php (for example)
  • put this code inside

<?php
/*
* Template Name: IFrame
*/
   $id = intval($_GET["ID"]);
   $post = get_post($id);
   var_dump($post);
?>
  • Then go to dashboard and create page iframe and in the sidebar where it says: template, choose now created template (Iframe)
  • save and go to url and time http://yoururl.domain/iframe/?ID=1

it should give you back your post

Of course you need to design your own template.

Leave a Reply

Your email address will not be published. Required fields are marked *