How can I reverse engineer a Permalink to Find the Page?

Addressing both your original question and the question implied by your comment …

Finding the page ID

Every post and page within WordPress is given an ID. By default, WordPress uses the ID in the link structure: http://www.example.com/?page=ID or http://www.example.com/?p=ID (for posts). You can change this to a more user-friendly structure called “pretty permalinks” that will use the page slug in the URL instead: http://www.example.com/my-page-slug.

In practice, though, these permalinks can become very long. This is bad for certain situations (i.e. posting to Twitter), so WordPress retains the shorter ID-based URLs as “shortlinks.”

You can figure out the shortlink for a particular post or page by navigating to that page, right-clicking, and selecting “view source.” Then look through the source for a specific section of meta tags:

<meta name="generator" content="WordPress 3.0.3" /> 
<link rel="shortlink" href="http://example.com/?p=2" /> 

This “shortlink” tag tells you that you’re looking for post #2.

Finding the page in WordPress admin

You’ve already discovered the easiest way to find a post or page – just search for the page slug when you’re in the admin. This will find it almost every time, or at least give you a small list of possibilities.

Another way is to use the ID you discovered above to jump straight to the post/page edit screen. Every post or page edit screen uses the following URL structure: http://example.com/wp-admin/post.php?post=ID&action=edit

Just substitute the ID you discovered above for ID in the URL and you’ll be taken to the post/page edit screen for that content.

Template Files

Page templates are defined by your theme. They’ll all be located somewhere in the /wp-content/themes/YOUR-THEME/ folder. The name of the page template (which you saw on the post edit screen) might give you a hint as to which file you’re looking for, but I can’t guarantee it.

Just know that all page template files will begin with the following code:

<?php 
/* Template Name: PAGE TEMPLATE NAME */ 
?>

So if you have more than one template file defined by your theme, looking for this tag will help you identify the specific one you’ll need to edit. This template will define the HTML and PHP code used by pages that specifically call out that particular template.

Leave a Comment