WordPress and PHP


In the last few weeks, we’ve learned some basic concepts on HTML5 and CSS. A simple analogy we can use as to how they work can be likened to writing a traditional letter sent via snail mail. HTML5 is like marking and dividing the content of the letter into sections like: the date, the greeting, the body, the closing, and the signature. CSS is what is used adds pizzazz to the is the way the letter is written: stylized handwriting, choice paper, and images and illustrations to enhance it. The result is a beautiful handwritten masterpiece ready to be sent and read by the reader. This week, we add on to our WordPress building blocks and learn how PHP comes into the picture.

To review, here’s how we defined PHP:

PHP (initially Personal Home Page tools)

PHP is a recursive acronym for PHP: Hypertext Preprocessor. It is a popular server-side scripting language designed specifically for integration with HTML, and is used (often in conjunction with MySQL) in Content Management Systems and other web applications. It is available on many platforms, including Windows, Unix/Linux and Mac OS X, and is open source software.

Adam Brown shared this simple and easy to understand explanation to tie it all up together:

When you view a webpage, the server (i.e. the site you are viewing) sends a bunch of HTML to your computer. Your browser (Firefox, Safari, Internet Explorer, whatever) then turns this HTML source into the pretty stuff you see in your browser. With pure HTML, every visitor to a website will see the same thing, no matter what.

For example,

if we make an HTML page with this content:

<p>Today is December 1st, 2007<p>

…everyone who visits the site will see this:

Today is December 1st, 2007

…even if it is not December 1st, 2007.

What if you want to modify that so it always shows the current date? That’s where PHP comes in. PHP is processed by your server (i.e. by the site you are visiting). The server evaluates any PHP in the page before sending anything to your browser. So if we write this in the web page:

<p>Today is <?php echo date(‘F jS, Y’); ?></p>

Then the server will change that PHP expression into the current date, then send that as HTML to your browser, which then does its part.

Remember: The server processes PHP, but the browser processes HTML.

PHP does not get sent to the browser, only the HTML that the PHP produces.

People sometimes wonder why their theme’s index.php file looks nothing like the HTML source they see in their browser. Well, now you know why.

(source: PHP 101- Adam R. Brown. Check out his website for more easy to follow tutorials.)

Why is it important to understand PHP? Because WordPress is written using PHP and requires it for operation.

Till next!


Note: Many of the articles on this site include affiliate links that may earn us a commission if you decide to buy the recommended product.