Embed Post in external page

I want to create a page that can be embedded in other sites with an embed script like this:

<iframe src="http://www.example.com/the_hidden_page?setting=set1&setting2=set2"></iframe>

The page will need to be ‘hidden’ so it does not appear in the menu on my site and it will need to accept a query string.

Read More

The URL in my example does not need to be exactly like this, something like /the_hidden_page/set1/set2 would be fine as well.

Related posts

3 comments

  1. Prerequisite: Custom Plugin

    First you’ll need a small plugin. Just copypaste it into a .php file, add it to some folder, zip and upload it to your installation an you’re done.

    What it does

    This small plugin only checks if the wpembed query part is present and if it is set to true. If both is the case and the request looks like for example

    https://example.com?wpembed=true
    

    then a custom template will be searched first in your child theme in your parent theme and, if found, will be used instead of any other template from the template hierarchy.

    <?php
    defined( 'ABSPATH' ) OR exit;
    /** Plugin Name: (#102480) WP Embed */
    add_action( 'template_redirect', 'wpse_102480_wpembed' );
    function wpse_102480_wpembed()
    {
        if ( isset( $_GET['wpembed'] AND 'true' === $_GET['wpembed'] )
        {
            include( locate_template( 'wpembed.php' ) );
            exit;
        }
    }
    

    In your (child) theme

    Just add another template file to your (child) theme named (in this example) wpembed.php. There you add whatever you want to be output when it is called. You can access query args via $_GET parameters or (maybe) even via get_query_var( 'key_name' );.

  2. You can add or remove pages from the menu as per your requirement. If you haven’t created a menu yet, create one in Appearence->Menus and then set that as primary menu and then add all the pages that you want to display in the menu section.

Comments are closed.