13 Jun An Introduction to PHP: How to Edit Your WordPress Theme
PHP, in its most basic form, spits out HTML, depending upon different conditional statements. For example, if a visitor is logged in, they will see a different HTML, as opposed to a visitor who isn’t logged in. PHP is the language WordPress is built with, and thus is the language all WordPress themes are built with.
WordPress makes it very easy for themes to add and manage content, with a ton of built in functions. Basically it’s a combination of HTML and PHP that make up your theme. It’s also important to know how the different files in your theme interact. Take a look at basic theme anatomy to learn more about that.
A couple things to note, before we jump into WordPress functions. PHP syntax starts with “<?php” and ends with “?>”, each line, however ends with a single semicolon (this tells the server to stop executing). If you see parentheses, it means a function is being called. The word echo means “spit out” the return value onto the page.
Here are some common WordPress PHP functions:
- get_header() – this function call includes the file header.php. You’ll notice it at the beginning of nearly every single template file within your theme.
- get_footer() – this function call includes the file footer.php. You’ll notice it at the end of just about every template file within your theme.
- get_sidebar() – this function call includes the file sidebar.php. Often times the difference between the full-width template, found in many themes, and the default template, is one will call get_sidebar() and the other won’t.
- the_content() – this, when used within the WordPress loop, will pull the content from the page. WordPress has set everything up to make database calls, and just knows what content to pull in.
- the_title() – this function call will echo out the title of the post or page.
Those are just five of the most common WordPress functions, and manipulating theme can come in handy when trying to edit your theme files. Thus, if you don’t want your title to appear on pages, you can navigate to page.php (appearance > editor) and remove the call for the_title().