I have a custom made Twitter stream on my site.
I want to have a permalink for each tweet which would go to a page which would display only the tweet – no other content – surrounded by my custom theme.
Ideally I would get WordPress to display a Page Template on a certain url (something like /tweet/<tweet_id>), but I don’t want to create a Page because it will appear in the main menu.
I’m happy to write a plugin but my Google-fu is failing help me to figure out how to display just that plugin’s content on a page.
You can do this by creating a “fake page” so to speak, where instead of creating the page in your dashboard area under
Pages -> Add New
then selecting a template from Page Attributes or by creating a template that matched the slug or id such aspage-{slug}.php
orpage-{id}.php
you instead use a combination of rewrite rules combined with hooking onto an actiontemplate_redirect
to achieve the desired result.You can see an exact example of this in my answer to this question.
I’ll copy in my snippets below but the full explanation should be read in my answer above.
Step 1:
Step 2:
Note: Some tweaking might be necessary to associate individual tweet IDs but we’d need to see your code that relates to the tweets.
These snippets go into your
functions.php
file. Naturally you should change any of the parameters that should otherwise meet your desired end point. So where you seeblog
becomeswhatever-you-want
etc. The template name in the second snippet should correspond to your desired template.I decided to use a Page and looked at how Exclude Pages hides them.
This is what I came up with (in
functions.php
):