Wow, I thought I had written this up somewhere, but because Ken asked, and he is doing cool stuff with his Connected Course

What is the Magic Box? Not much magic, but it is meant for the WordPress / Feedwordpress type aggregated sites I have been building the last few years (see my how to series). In the more recent iterations, these sites have a signup form powered by Gravity Forms and custom code that automatically adds people’s blog feeds to the site’s Feed WordPress data.

The Magic Box was something I added to help people figure out their RSS feeds, using some code that fetches the source of that URL and examines it for tell tale signs of RSS (meta tags). It works best on main blog URLs, getting feeds from category and other assorted partial bits of blogs is problematic (that’s a whole other blog post, in the RSS is Great and Messy at the Same Time category).

So typically I link to the Magic Box in the place where we ask for a blog’s RSS feed

From the Connected Courses blog sign up form

From the Connected Courses blog sign up form

I first made a magic box for the VCU Thought Vectors course, then Connected Courses, Networked Scholars 2014, and most recently for the You Show gig I am doing here at TRU.

They all do the same thing, and you can use them any time. If I knew I was going to keep using it, I might have been smart and hosted it somewhere and just linked as needed, but it’s nice to have it within the navigation of the host course site.

Enough Intro, Alan, How do I make One?

NOTE: Having some issues with the plugin that formats code- get all of the code fragments shown below, you can download as text file.

If I was a bit more deft, I might do it as a plugin, but I don’t see a sign of that happening. So to make one you have to be able to edit your theme’s template files.

These first bits need to go in your functions.php file. The first function cdb_parameter_queryvars lets me pass parameters to my templates via the URl string, in our case, the value of the URL field in the form.

The second function feedSearch actually requests the HTML source of the web site represented by $url and more or less brute forces looking for the link tags that contain RSS feed addresses. Some sites will have several but in my experience the primary feed is first (wobbly assumption).

The funny thing is parts of this came from code by Martin Hawksey that he attributed back to me and Martha Burtis on the ds106 site. Some sort of boomerang attribution.

Next you need to create a new WordPress Page that will host the form, name it whatever you like, but make sure it’s slug (the URL field) is exactly magic-box You can put what ever you like in for some introductory content, and add images. The Magic Box functionality is added via the template code below.

Save that page. It does nothing, yet. We have not added any magic.

Now what you want to do is to look for a file in your WordPress theme called page.php which is the general template for any WordPress page. Make a copy of that and save it as page-magic-box.php. This takes advantage of the WordPress Template Hierarchy for Pages.

Our new template will be used only for a page with a slug name of magic-box.

This first bit of code gets executed before we do any thing for the page layout, it should appear before your template’s code for

It does all the logic when someone submits the form- it makes sure there is something entered, and then sends the value to the feedSearch function. if it gets something back, it sets up appropriate feedback response.

The rest of this comes after the part of your theme that has something like, and finally echoes the appropriate response.

This is the part that puts in the contents of what every you edited in the Page contents (e.g. the instructions for the box). We then insert a small web form to enter a URL. The wp_nonce_field nonsense is something WordPress does to make sure it only responds to forms submitted from this site (I think).

Yes there is probably 500 hundred ways to code this better. But it has worked for me plenty of times. I can certainly hoist it on a site somewhere if someone might find use for it (e.g. it could be used as a link or even iframe for any web site, not just wordpress).

Yeah, I should do that.

Top / Featured Image Credit: Wikimedia Commons image by Shawn from Airdrie, Canada (The magic box) [CC BY-SA 2.0 (], via Wikimedia Commons


  1. I mucked about a bit to get it to play happy with the Beaver Builder child theme but it is almost there.

    A note and a question:

    #1 There are some spaces between the < and ? on lines 11 and 13 on the form that breaks things. Also something on line 3 with the php call to get the blogurl so I just set that to empty string

    #2 How do you get the blue box to show up say on after submitting a URL? Is that in the css?

    Mine just dumps the message up at the top after I figured out where to place the output.

    1. I tried to do this too quickly!

      (#1) Something in the plugin that formats the code is inserting extraneous blanks. Will sort it out or just put on github. Line 3 is critical, and the form will not work of you set blog URL to empty. That is what fetches the value from the form.

      (#2) Yes, I use some CSS to generate the boxes.

      Will email code.

Leave a Reply

Your email address will not be published. Required fields are marked *