• Resolved Tim Boulley

    (@tboulley)


    My Plugin Structure:

    test-plugin (main plugin folder)

    • assets (folder)
    • includes (folder)
    • languages (folder)
    • test.php (the file I want my iframe to load)
    function test_plugin_admin_sub_page(){
    	?>
    <style>
     iframe {
     width: 1px;
     min-width: 100%;
     }
     </style>
    
    <div class="wrap">
    <iframe id="testIframe" src="test.php"></iframe>
    </div>	
    <?php
    
    }

    Using the code above WordPress cannot find the “test.php” page, and since the iframe is in HTML code I can’t use the typical ‘plugin_dir_path( FILE )’ function. How can I create an iframe to display a local page located in the same plugin folder rather than a remote page?

    Thank you in advance for any help that can be provided!

    • This topic was modified 1 year, 2 months ago by Tim Boulley.
    • This topic was modified 1 year, 2 months ago by Tim Boulley.
    • This topic was modified 1 year, 2 months ago by Tim Boulley.
    • This topic was modified 1 year, 2 months ago by Tim Boulley.
Viewing 4 replies - 1 through 4 (of 4 total)
  • What is used to call the function test_plugin_admin_sub_page()?

    Thread Starter Tim Boulley

    (@tboulley)

    Hi Threadi,

    Thank you very much for your reply! Here is the code I am using:

    add_action( 'admin_menu', 'test_plugin_admin_menu' );
    
    function test_plugin_admin_menu() {
    	add_menu_page( 'Test Plugin Menu', 'Test Plugin', 'manage_options', 'test-plugin/test-plugin-admin-page.php', 'test_plugin_admin_page', 'dashicons-art', 6  );
    	add_submenu_page( 'test-plugin/test-plugin-admin-page.php', 'Test Page Menu', 'Test Page', 'manage_options', 'test-plugin/test-plugin-admin-sub-page.php', 'test_plugin_admin_sub_page' );
    }
    
    function run_test_plugin() {
    
    	$plugin = new Test Plugin();
    	$plugin->run();
    
    }
    
    function test_plugin_admin_page(){
    	?>
    
    <div class="wrap">
    
    <iframe id="TestPluginFrame" style="width:100%;height:1000px;border:0;" src="https://mysite.com/test.php"></iframe>
    </div>
    	<?php
    
    }
    
    function test_plugin_admin_sub_page(){
    	?>
    <style>
      iframe {
        width: 1px;
        min-width: 100%;
      }
    </style>
    
    <div class="wrap">
    <iframe id="testpageIframe" src="https://mysite.com/test.php"></iframe>
    </div>	
    <?php
    
    }
    
    run_test_plugin();
    • This reply was modified 1 year, 2 months ago by Tim Boulley.

    Ah, ok, very simple actually:

    <iframe id="TestPluginFrame" style="width:100%;height:1000px;border:0;" src="<?php echo trailingslashit(plugin_dir_url(__FILE__)); ?>test.php"></iframe>
    Thread Starter Tim Boulley

    (@tboulley)

    THANK YOU!! That did the trick. ??

    Happy Holidays to you and yours!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How can I iframe a local page rather than a remote page?’ is closed to new replies.