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.
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 totrue
. If both is the case and the request looks like for examplethen 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.
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 viaget_query_var( 'key_name' );
.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.
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.