How to Dig Into the PHP Behind Your Blog in 7 Steps
January 31st, 2010 by
In one of my early blog designs, my client asked me to replace the “newer entries” and “older entries” links in their home page with arrow images.
As you may already know, putting images as the previous posts link is not a difficult task.
It made me curious however, how the next_posts_link function works, and how customizable it really is.
So for the job I harnessed 2 of my favorite tools – Adobe DreamWeaver and FireFox with FireBug installed.
Let’s see how the diggin’ is done:
FireBug – Inspecting the HTML
- Locate the “Older Entries” link (or any variation of it) in the any blog’s homepage.
- Scroll down to that link, right click on it and selected “Inspect Element”.
The “a” tag becomes highlighted.

Now the key is to find something unique near the “a” tag we can use to search by in the PHP source … the <div class=”navigation”> is a good bet.
Here you can see the PHP code behind a default WordPress homepage (index.php file).
I copied lines 28-31 and put it below. looks familiar, right?? the same navigation div, but instead of HTML, we see the PHP behind it.
In line 2 (above) you can see “next_posts_link” – this is the PHP function the creates the “a” tag.
So now we found the PHP surface, let’s dig a little dipper…
DreamWeaver – Detecting the PHP Function
We want to find out what the ‘next_posts_link’ is all about, so we need to search for “function next_posts_link” note
- Open your local WordPress site in DreamWeaver (if you don’t have one, check out this post).
- Click CTRL + F and select “Entire Current Local Site” from the drop down.

- Type in “function next_posts_link” and click “Find All”.
You can see that a single search result is found and it’s in wp-includes/link-template.php file. - Double click on the search result, to jump to this function:
function next_posts_link( $label = 'Next Page »', $max_page = 0 ) { echo get_next_posts_link( $label, $max_page ); } - As you can see in line 2 (above), the function ‘get_next_posts_link’ is called, so now let’s search for “function get_next_posts_link”. The search result is displayed below.
function get_next_posts_link( $label = 'Next Page »', $max_page = 0 ) { global $paged, $wp_query; if ( !$max_page ) { $max_page = $wp_query->max_num_pages; } if ( !$paged ) $paged = 1; $nextpage = intval($paged) + 1; if ( !is_single() && ( empty($paged) || $nextpage <= $max_page) ) { $attr = apply_filters( 'next_posts_link_attributes', '' ); return ''; } }
That’s it! we are done digging and found the source to that HTMl ‘a’ tag (line 11).
This is an efficient way to learn how wordpress works, and the fastest way I know to learn some basic php.
Once you get used to it, you can become a wordpress developer a lot faster than you think.
So now what??
Although it may seems the quickest way to customize wordpress, don’t be tempted to change core php, this is not the right way to do it. Check out this post to read about the alternatives.

Although you could learn loads about the structure by digging around the core of WordPress, for someone who doesn’t even know basic PHP it could be very complicated and overwhelming as there are a lot of calls to functions from functions and custom classes etc. Plus like you said there is no need to ever edit the core.
A great place to learn PHP is phpvideotutorials.com.
Thanks, Frank.
Even though there is no need to edit WP core files, I highly recommend learning basic PHP for bloggers.
This knowledge becomes handy when you want to customize WP functionality using the functions.php file.
There is no need to learn object oriented PHP with classes etc, just to understand the very basics, and I think that digging into WordPress this way may be the best method to understand how the system works as well as gain some fundamental skills in PHP
Very useful post. I don’t know php but I understand the gist and some of the terminology of programming languages, so this is very useful. I didn’t understand some of the code when I look into it: I’m using WP 3.0 and the default theme php looks different, although still contained within wp-content\link-template.php:
function next_post_link($format=’%link »’, $link=’%title’, $in_same_cat = false, $excluded_categories = ”) {
adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, false);
Entering function_adjacent_post_link:
function adjacent_post_link($format, $link, $in_same_cat = false, $excluded_categories = ”, $previous = true) {
if ( $previous && is_attachment() )
$post = & get_post($GLOBALS['post']->post_parent);
else
$post = get_adjacent_post($in_same_cat, $excluded_categories, $previous);
if ( !$post )
return;
$title = $post->post_title;
if ( empty($post->post_title) )
$title = $previous ? __(‘Previous Post’) : __(‘Next Post’);
$title = apply_filters(‘the_title’, $title, $post->ID);
$date = mysql2date(get_option(‘date_format’), $post->post_date);
$rel = $previous ? ‘prev’ : ‘next’;
$string = ‘‘;
$link = str_replace(‘%title’, $title, $link);
$link = str_replace(‘%date’, $date, $link);
$link = $string . $link . ‘‘;
$format = str_replace(‘%link’, $link, $format);
$adjacent = $previous ? ‘previous’ : ‘next’;
echo apply_filters( “{$adjacent}_post_link”, $format, $link );
}
I would never attempt to rewrite this code because I don’t understand lots of it. Still it’s good to see what does what.
Hi Heather. This is a core file and it’s not recommended to change it. However, as you say, if you understand the idea it makes it easier for you to learn some PHP.
Thanks Omer. I thought it was a core file. I’d steer clear anyway! I note in another post that you say more than 12 plugins is too much. I have more than that, but obviously I’d like to reduce them. I have things like WP > Twitter, and Social bookmarking. I take it there will be stuff available online. I’m just very wary of adding in code when I’m not too sure of what I’m doing!
You never get too old to learn something so very easy. FireBug and DreamWeaver – never though about that. Thanks.
/ Jonas Lundman
You are welcome Jonas.