Need a WordPress website this weekend? Start here...

DIY WordPress: What You Need to Know About PHP if You Don’t Yet Know a Damn Thing

(Reading time: 6 – 9 minutes)

WordPress can be considered a dynamic web application. What that means depends a little bit on who you talk to, and what you are using WordPress to achieve. (Look for related reading at the end of this article.)

What “dynamic web application” means for this article is a web page resulting from an unholy fusion of HTML, CSS, PHP and MySQL. And Javascript. Can’t forget Javascript.

5 different langguages. That’s crazy. Seriously, it’s crazy. Back in the dinosaur days (1990s), it was plenty to master one programming language per application.* You could even spend most of a career just in one or a few languages.

Anyway, if you’re still with me, you probably know a little bit about HTML and CSS by now. It turns out that for WordPress, you don’t need a lot of Javascript or MySQL for tweaking themes and plugins. Helpful, they are, but not necessary.

What you need now is a little PHP, so that’s where we’re going next.

“Why should I care about PHP?”

You continue, despite your better judgement, to read Website In A Weekend on a regular basis. Which means by hook or by crook, you’re at least partly in the do-it-yourself camp. You may not want to camp in DIY, but there you are. So you should care because if you don’t, you’re gonna mess something up sooner or later.

Sidenote: If you whitescreen WordPress, that is, all of sudden, the only thing displayed is a blank white page, you almost 100% surely have a syntax error in your PHP code, and that syntax error is almost surely a missing semi-colon “;”.

And it won’t be pleasant.

So that’s why you should care.

WTH is PHP, anyway?

PHP is a recursive acronym, meaning PHP Hypertext Preprocessor. For more on recursive acronyms, I suggest Wikipedia.

PHP is a programming language that slides in and around HTML to do a lot of tedious dirty work so you don’t have to. PHP code intermingled with HTML often appears ugly. In programming, something appearing ugly often is ugly. One of the weaknesses of PHP is that some of this ugliness can’t be helped. It was designed in.

PHP is a module that plugs into your web server that translates (preprocesses) PHP files into HTML (hypertext). The PHP interpreter is different than the web server. You can run a web server without PHP, but you can’t serve PHP over the web without a web server.

PHP is all that and more!

PHP Hypertext Preprocessor

From the above, PHP the programming language is what’s of most concern to you, right here and right now. The language is what you’re going to see when you’re poking around in WordPress. Here’s the basic concepts.

  • PHP language syntax. PHP syntax derives from the family of C like languages. If you know already know C, you will pick up PHP pretty quick (but you probably already know that). If you don’t know C, no worries, it’s not that important. The point is, there’s history and meaning behind PHP syntax. It didn’t sprout from someone’s forehead, ex nihilo.

    Current versions of PHP are “object-oriented.” But really, PHP is procedural, object-oriented capability was bolted on, not designed in.

  • Understand variable scope. Understanding variable scope is critical. If you have programmed before, you may need to unlearn some assumptions, like global variables not acting how you think they should. Variable scope in PHP still trips me up. If you have little programming experience, you won’t have to unlearn anything. That’s a good thing.
  • PHP paths are critical. When you write an application or even tweak a plugin for WordPress, you need to know how WordPress and PHP find things like files and images you want to deliver to your readers. WordPress does a pretty good job of standardizing paths. Spend the time to figure that out.
  • Understand single and double quoting. Single and double quoting in PHP behave slightly differently, but these small differences are important. Sometimes single and double quotes can be used the same way, other times, they can’t be used the same way. Most people develop their own scheme for when and how to use each type of quoting.
  • WordPress and PHP APIs are different. A collection (library) of functions is called an Application Programming Interface (API). When you’re just starting out, it’s critical to figure out the difference between functions that are part of PHP and functions that are part of WordPress.

Here’s four functions you absolutely must know for effectively programming in WordPress. I suggest either memorizing these functions (smart) or have their definitions on speed dial (not as good, but it’s how I do it).

  • dirname: returns the directory path to the file given as argument. This is the directory on the server, not the URL path. PHP function.
  • basename: returns just the file name for a given path. Dual to dirname. PHP function.
  • add_action: adds a specified function to a WordPress action. Example: if you want to print your own meta tags into your web page head element, create a function and use add_action to tell WordPress where to print the output of your function. See Line 20 in Anchor Text Plugin.WordPress function.
  • add_filter: modifies text before printing that text to a WordPress page. For example, WordPress uses a filter to automatically add paragraph breaks to your blog posts. (Which some people really hate, but what can you do?). WordPress function.

Low Mercury from Groovera Chilled Web RadioBy the way, I just got a nice email from Tim Lumen, who operates Groovera.com. Curiously, I just happen to be listening to Low Mercury right at this very moment. Low Mercury is super-chill, great for those days when Trance, Techno and Breakbeats is just a little too much. If you’re in a kick back writing mode, check ‘em out. Groovera is 100% listener supported, and worth it. If you like what you hear, donate or subscribe. If you’re in budget mode, give Tim a little link love. Or both!

Related reading

Here’s some articles you might like from 2009:


*Make and cpp don’t count. La la la I can’t hear you. Never let facts interfere with a good story.

SEO Anchor Text SEO Anchor Text SEO Anchor Text SEO Anchor Text

(Reading time: 3 – 5 minutes)

Do I have your attention?

Good.

I’ve mentioned this before, anchor text matters.

If linking is the door to higher search results, anchor text is the key that unlocks that door.

I know this for several reasons. I rank pretty well for a couple of long tail terms. I also watch as many of those free SEO videos as I can from people like Brad Callen, Andy Jenkins and the like. You know, the Stompernet guys and big time internet marketers. They give away a lot of good stuff for free. And if they’re a-givin’ I’m a-takin’.

Using anchor text naturally, such that it doesn’t break the flow of your prose (and sound all weird) is a bit of an art.

But first you have to get the anchor text (if you are linking), or find a way to provide it people who want to link.

1. Ask for anchor text

If you aren’t sure what anchor text to use when linking to an article, ask the article’s author.

If you’re an author, provide anchor text information to people who want to link to you.

If you find yourself being linked to with unsuitable anchor text, here’s what Erica Douglass does:

I send them an email thanking them for linking to my blog, and then say “Instead of erica.biz as your link text, can you put ‘starting your own business‘?” (I’ll also often throw in an entire sentence with the <a href=""></a> etc. already in there.

Sometimes it works. Sometimes it doesn’t. I’ve gotten most of my good rankings from guest posting and putting the SEO’d text in my blurb. I show how to do this in Guest Post Secrets.

2. Using SEO keyword metadata

STOP.

I’m not going to write what you think I’m going to write about keywords. Instead, I’m going to make an offer. First:

Use your meta keywords to specify your preferred anchor text.

That way, when I want to link to you, I’ll know what you want to rank for. I just look at the source for your page, extract what I need. Easy.

Here’s the offer: if you want to link to one of my articles, and you find that it (the article) has no keyword metadata (there are plenty, too many), email me, I’ll add keywords you can use for anchor text, and send you a free copy of Blog Post Engineering when I get the trackback from your link.

3. Let’s plug it in

If the notion of specifying keyword metadata is simply too repellent, I offer a tiny plugin for your amusement.

Since it’s Tuesday, we can go technical.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
 * Plugin name: Fast Anchor Text
 * Plugin URI: http://website-in-a-weekend.net/seo-anchor-text
 * Description: Set desired anchor text as custom field.
 * Version: 0.1
 * Author: Dave Doolin
 * Author URI: http://website-in-a-weekend.net/
 */
 
function anchor_text_meta() {
 
   if (is_home()) return;
 
   global $post;
   $anchor = get_post_meta($post->ID, 'anchortext', true);   
   if ($anchor) {
      echo "<meta name=\"anchortext\" content=\"$anchor\" />\n";  
   }
}
add_action('wp_head', 'anchor_text_meta');
?>

If you don’t like plugins, and you prefer messing around with functions.php (or custom_functions.php in Thesis theme), you can just paste the functional parts into those files.

Here’s a screenshot of how to use it:

Custom anchor text

Key in blue box, anchor text in red box

Here’s the plugin file: anchor.zip.

Blog Maintenance Challenge

Believe it or not, I am slowly yet surely adding material to the Blog Maintenance Challenge. Dealing with keywords and anchors is definitely on the curriculum.

I’ll have some videos over there too.