Lead image for Getting Started with WordPress Development: A Developer's Guide

Getting Started with WordPress Development: A Developer's Guide

WordPress is the most popular content management system (CMS), supporting 41 percent of all websites worldwide.

Its easy-to-use interface and multiple plugins as well as other features make it a good choice for developers. You can customize a WordPress site in countless ways, providing a lot of flexibility for you and your clients.

If you’ve been considering using WordPress, now is a good time to start. In this article, you’ll learn more about how WordPress can help you as a developer and how you can use it to supercharge your products.

Why Do You Need WordPress as a Developer?

People around the world use WordPress to build blogs, portfolios, e-commerce stores, and other sites. Because of its huge userbase, there is a lot of demand for outstanding WordPress developers who can build custom solutions for clients and tweak the core software. WordPress developers can earn over $100,000 USD a year, making it a profitable side gig or full-time job.

As a developer, WordPress provides you with a lot of creative freedom. The software is very extensible, thanks to its multiple plugins and themes, and you can also easily develop whatever you want on top of the existing platform.

How to Get Started

For WordPress development, you should know the fundamentals of programming. Since developing for WordPress is similar to web programming, the languages used for both are basically the same.

You’ll need to know the following languages:

  • HTML: The backbone of the internet. The markup language provides basic structure and layout to your web page, and you’ll use it every time you build a website.
  • CSS: While HTML provides the layout of your website, CSS helps make your site look beautiful with colors, fonts, animations, and other elements. Frameworks like Bootstrap and Tailwind can be used to write code more quickly.
  • JavaScript: Another language you’ll find on almost every website. It adds interactivity and logic to your web pages.
  • PHP: The language on which the the base of WordPress is built. It’s a backend language, so you’ll be using it for a lot of the logic that runs behind your site on a server.
  • SQL: The language that you’ll use to work with databases.

You’ll also need to get familiar with the elements of the WordPress platform, including plugins, themes, and child themes.

What Is a Plugin in WordPress?

Plugins are tools that can be used to extend the functionality of the WordPress platform. The variety of plugins is part of what makes WordPress so extensible and loved among users.

If you’re building an e-commerce store, for example, you’ll need to accept payments from customers. The core WordPress software doesn’t provide this functionality out of the box, but you can download a plugin from the WordPress marketplace to add the feature.

Plugins can also be used to add analytics, speed optimization, and design elements to your site. There are more than 59,000 plugins on WordPress, and there’s always room for more.

How Do You Create a Plugin in WordPress?

You can also create your own plugins. To do this, there are a few terms you should learn:

  • Hooks allow you to access a specific point in the WordPress core and change its behavior. For example, there’s a hook for when a user activates the plugin, another for when the plugin is uninstalled, and so on. Hooks come in two forms: actions and filters.
  • Actions allow you to execute your own code when a preexisting hook runs in WordPress. For example, if you want to share your post to social networks when the admin publishes it, you can write an action for that.
  • Filters allow you to edit the content that WordPress returns upon running some hook. You can’t add anything to that response, but you can edit the response. This is useful when you need to edit the title or the content of a web page.

For more details, check the WordPress Developer Resources.

Creating a Plugin

To make a plugin, first create a local copy of WordPress on your machine and access your WordPress installation files using FTP or your hosting provider.

Create a directory in the /wp-content/plugins/ folder named after your plugin. In Unix, it would look like this:

wordpress $ cd wp-content/plugins
plugins $ mkdir plugin-name
plugins $ cd plugin-name

Create a new PHP file for writing the plugin code:

plugin-name $ touch plugin-name.php

Add this metadata at the top of your PHP file to tell WordPress what your plugin is about:

/*
 
Plugin Name: your-plugin-name
 
Plugin URI: your-plugin-website
 
Description: short-description-of-what-your-plugin-does
 
Version: plugin-version
 
Author: developer-name
 
Author URI: developer-website
 
License: plugin-distribution-license
 
Text Domain: unique-identifier
 
*/

Before you start coding your plugin, there are a couple of things you should know:

  • You can create the plugin’s codebase from scratch, all in one file or divided over several files.
  • You can also play around with existing plugins by forking them to your installation, or build on top of an existing plugin by adding features and fixing bugs.

Best Practices for Creating a Plugin

When creating a plugin, you should keep the following in mind:

  • Use a unique prefix for all the functions, variables, and classes in your code to prevent it from getting mixed up with the code of other plugins.
  • Use object-oriented programming (OOP) for better structure and readability.
  • Use a well-defined folder structure to make it easier for others to contribute.
  • Take plugin security seriously. Use measures like user capability checks, data sanitization, and nonces to prevent hacking.
  • Use internationalization for easier accessibility for people from other countries.
  • Build your plugin in a local staging environment instead of a production environment to avoid crashes and accidents.

What Is a Theme in WordPress?

After plugin development, the next most popular choice for developers is theme development. A WordPress theme provides users with a structure, layout, and other details like colors and fonts that they can use to further build their website. The themes you create allow the average user to build a website quickly without having to write a single line of code.

With a theme, you can give your website a unique look.

How Do You Create a Theme in WordPress?

Creating a WordPress theme is easy. First you’ll need to know how WordPress works behind the scenes to display web pages.

WordPress follows a hierarchy to find a template to display the URL the user is at. For example, if you’re on the page https://wordpress.org/my-url, this is how WordPress searches for the correct template:

  • First, WordPress looks for a file called /theme-name/page-{slug}.php, or /theme-name/page-my-url.php in this example.
  • If the above file isn’t found, WordPress instead uses the page ID and looks for /theme-name/page-{id}.php. If the page has an ID of 6, it looks for /theme-name/page-6.php.
  • If the above is also missing, then WordPress looks for a generic template. For pages, it looks for page.php; for categories, category.php; and so on.
  • Following that, singular.php is a generic file for rendering pages or posts. For category pages, WordPress instead looks for an archive.php file.
  • Your index.php is the last option. This file cannot be absent from your theme (it’s compulsory), so there is no scope for searching further.

You should also be familiar with the Loop, WordPress’s system to iterate over your database to fetch and show the content specified in your theme’s code.

###Classic Themes

Creating a Classic Theme

The following is a high-level process for creating a theme. It assumes that you’ve already set up a staging environment for development purposes.

First, open your website’s files and navigate to /wp-content/themes/. Create a directory named after your theme:

wordpress $ cd wp-content
wp-content $ cd themes
themes $ mkdir your-theme-name

In /wp-content/themes/your-theme-name/, create styles.css and index.php:

your-theme-name $ touch styles.css
your-theme-name $ touch index.php

These files are the bare minimum you need to build a theme. styles.css styles your website and shows metadata about your theme on the Themes page in WordPress, and index.php renders the frontend layout of your website.

Apart from these two files, you can create an optional functions.php file to contain PHP functions for all the fancy stuff on your website. JavaScript files, images, and other elements are optional too.

Finally, use PHP and HTML in these files to create your theme. You can either code the theme from scratch or use a starter framework like Underscores or Genesis.

What Is a Child Theme?

Child themes are themes that inherit functionality and styling from their parent theme. As a developer, you can create a parent theme and multiple child themes based on that parent theme, then extend and modify them freely.

The best part about using child themes is that you can change them without having to worry about those changes being overridden by an update. You can also safely update your parent theme while retaining the changes you made in your child theme.

Block Themes

Block themes are a new feature introduced in WordPress 5.9. They break the typical workflow of working with a theme. Instead, they use blocks, as the name suggests, and are a part of [Full Site Editing.] (https://developer.wordpress.org/block-editor/getting-started/full-site-editing/)

How Is a Block Theme Different from a Classic Theme?

There’s some fundamentals that are same for both, block themes, and classic themes. Like, both of them use the template hierarchy to display the desired files, both can use the theme.json file.

The differences are pretty visible as a developer though. Classic themes used PHP to display all the content and layout, whereas Block themes use HTML for the same purpose. PHP is used as a fallback in case WordPress can’t find the HTML file. The WordPress Loop is also gone and the query loop block is used. It’s used to display posts/pages based on specified parameters.

In other words, block themes replace everything PHP based to blocks.

Why Use a Block Theme?

Block themes are better than Classic themes to develop due to various reasons like:

  • Better loading performance.
  • Accessibility features are automatically put in place without you, the developer, having to do extra work.
  • Easier to edit for the user

How to Create a Block Theme?

Two things that are essential for creating any theme are: style.css and index.php. With Block themes, you need just one more required filed: index.html inside your templates folder.

Template parts like your header or footer are optional and can be placed in parts folder. You can also add additional files like you would with Classic themes.

After that, you can setup your theme inside functions.php by adding support for block features like this:

if ( ! function_exists( 'myfirsttheme_setup' ) ) :
/**
 * Sets up theme defaults and registers support for various WordPress features.
 *
 * Note that this function is hooked into the after_setup_theme hook, which runs
 * before the init hook.
 */
function myfirsttheme_setup() {
	// Add support for block styles.
	add_theme_support( 'wp-block-styles' );

	// Enqueue editor styles.
	add_editor_style( 'editor-style.css' );
}
endif; // myfirsttheme_setup
add_action( 'after_setup_theme', 'myfirsttheme_setup' );

You can also refer to this page.

Next, you can include CSS and JavaScript in your block themes too. The rest of process of coding the theme up is the same.

And, that’s just about it! Great job!

Read the full docs for a deeper dive down

Best Practices While Creating a Theme

Keep the following in mind while working on your theme:

  • Use well-structured, error-free PHP and valid HTML.
  • Create different folders for different types of files, like images, JavaScript, or templates.
  • Familiarize yourself with the template hierarchy.
  • Make sure to follow internationalization for your themes.
  • Debug your WordPress theme with define('WP_DEBUG', true) before releasing it to the masses.
  • Make sure that your theme is responsive and as fast as possible.
  • Use child themes while modifying existing themes.

Hosting Your WordPress Website

Now that you’ve developed your WordPress website, you need to host it on a server. You can use WordPress to create your website, but it isn’t meant for hosting.

The following are some options for hosting your site.

WordPress.com

Remember that WordPress.org and WordPress.com are two different platforms.

WordPress.org is open source, free software that can be used to build websites. WordPress.com, on the other hand, is a complete solution that helps you build websites and host them. WordPress.org is open-source and it is maintained by the WordPress community that contributes to it. WorPress.com on the other hand is owned by a company called ‘Automattic’.

WordPress.com isn’t your usual WordPress hosting platform. It comes with enterprise-grade security, built-in tools for sharing, stats, and SEO; premium themes, best-in-class support, and it’s the fastest WordPress and WooCommerce host on the market. What else could you ask for?

There is a free, limited version and two paid tiers:

  • WordPress Starter: $5/month
  • WordPress Pro: $15/month

The paid plans come with a 14-day money-back guarantee too.

Apart from WordPress.com, some of the other hosts we recommend are:

  • Bluehost: Powers over 2 million websites and has tools for beginners like 1-click installation, free domain name, email, FTP, and more.
  • Dreamhost: One of the best web hosts for beginners with affordable plans and features like automatic updates, free SSL, free privacy protection, 1-click installations, automatic backups, etc.
  • Siteground: If you’re looking to scale your WordPress website, Siteground can be on the top of your list. It comes with fine tuning for WordPress out of the box, automatic migrations, 24/7 support and more.

Conclusion

You should now have a good sense of how to create your own plugins and themes to customize and stylize your WordPress site. WordPress offers enough flexibility that you’re only limited by your imagination.

In addition to the above hosting options, there are plenty of other platforms on the market you can use to launch your site to the world.

Once you know the basics of WordPress development, you can create whatever type of site you like to meet the needs of any number of clients.

Naman Bansal

By Naman Bansal

Naman is an aspiring software engineer and freelance writer who is proficient in Python, C, Flutter, Dart, HTML, and CSS. He is also a published author on Amazon.