I am trying to iframe a template in WP e.g.
<p><a class='iframe' href="<?php bloginfo('template_directory'); ?>/training-form.php">Book Now</a></p>
This gives me a blank page, but if I do:
<?php get_template_part('training', 'form'); ?>
This displays the form, in the page
I thought it might have been a permissions, so I set the template permissions (via ftp) to 644 but still no luck! Any ideas?
Well, it can’t and won’t work.
You should think how iframe really works. All it does is send a request to server with given URL (src parameter) and display response.
Why inserting
<?php bloginfo('template_directory'); ?>/training-form.php
as src wouldn’t work? Just go to this address and see, what you’ll get. Nothing or some trash. Why? Because this is what that single PHP file prints out.Remember that you are accessing template file directly, so there are no WordPress global variables (no
$wp_query
,$wpdb
and so on) and no WP functions available (i.e. callingesc_attr
will cause PHP Fatal Error).So you have to put a page url inside iframe. Also you can’t display only part of this page.