1

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.

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.

4
  • Thanks. Nothing because I have no idea where to start. Jun 10, 2013 at 8:07
  • Actually, that is not true. I did try generating the embed code through an AJAX call. However, even though I used nopriv, it would not work if the user was not actually logged into the site. So I decided that may not be the best approach. Jun 10, 2013 at 8:08
  • How do you output your menu?
    – kaiser
    Jun 10, 2013 at 8:13
  • I am just using the 20-11 theme. I am not really familiar with what it does. However, I would rather not modify the theme if possible. Jun 10, 2013 at 8:19

3 Answers 3

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' );.

4
  • Thanks. This looks perfect. I will not be able to try it out until tomorrow, and I will come back to accept. 2 quick questions; 1 - This will work even if the user is not logged in? 2- when I write the template PHP, it will be able to access all the normal WP variables such as $wpdb? Jun 10, 2013 at 8:36
  • Ad 1) Yes, unless you cover parts with is_user_logged_in(). Ad 2) Yes, it loads WP core as normal.
    – kaiser
    Jun 10, 2013 at 10:19
  • I have an non-WP question. Why did you use 'true' === $_GET['wpembed'] instead $_GET['wpembed'] == true? Jun 10, 2013 at 10:23
  • The first version 'true' === $_GET['foo'] is a "Yoda" condition with a strict check. A Yoda condition avoids the mistake that you only use one = mark and accidentally assign the value to the $_GET-variable. The strict (three ===) forces PHP to not only check the value, but the type (string, int, etc.) as well. This brings PHP closer to a type safe language (like C for example), is faster and avoids having typecasting and such non sense.
    – kaiser
    Jun 10, 2013 at 12:07
1

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.

5
  • Thanks for the response. However, as stated in the title of my message, I need a page that DOES NOT appear in the menu. Jun 10, 2013 at 8:10
  • you simply create a menu and don't add that page in the menu section, so it will not appear in the menu section.
    – suvajit
    Jun 10, 2013 at 8:12
  • I'm not sure what you mean. I created a new menu, which did not show-up anywhere on the site, which is good, and I added my page to it. HOwever the page still showed up in the main menu. I set the parent to NO PARENT. Jun 10, 2013 at 8:18
  • Once you created a new menu, select the menu as the primary menu. You will get in the theme locations block. you will see primary menu written there and a dropdown along with it. in teh drop down select the menu you want to display in the front end
    – suvajit
    Jun 10, 2013 at 8:24
  • 1
    definitely, as suvajit says, use the Appearence->Menus. You will build the main menu (as well as others if you need to), adding the pages you want to show in your site. And you simply DON'T add the pages you DON'T want to see in the menus. codex.wordpress.org/WordPress_Menu_User_Guide codex.wordpress.org/Appearance_Menus_Screen codex.wordpress.org/Navigation_Menus codex.wordpress.org/Function_Reference/wp_nav_menu ...and related... Jun 10, 2013 at 10:58
0

Use Exclude Pages from Navigation by Simon Wheatley. Edit your page and uncheck the box Include this page in lists of pages in section Exclude Pages. Save page. That's all.

2
  • This is to exclude your page from results of wp_list_pages functions which is used by twentyeleven theme to build a menu. Jun 10, 2013 at 15:15
  • To properly handle GET parameters and show the content create custom template page-your-page-id.php. The name of this template is significant as it will be used automatically ( no special checks neccessary ). Jun 10, 2013 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.