Create a local WordPress site
First off, if you don’t already have it installed, download and install the program WP Local. It allows you to create and work on WordPress sites locally on your own computer.
Then, create a new site for your development project. You might want to makes sure the settings for your local site match the settings for the hosting you are or will be using for your live site. For example, you might want to choose a specific PHP version. For most use cases, going with the recommended settings when creating a new site will work just fine. Enable «One-click admin», and use the WP Admin button to enter the site logged in as an admin, for quicker access and not having to remember your password.
Import content from your live site
If you already have a live site, now is the time to use the plugin All-in-One WP Migration and Backup to move content from your live site to your local site. There are other options, but this is the one I am familiar with. Install it on your live site, and export the site to a file. Depending on the size of your site, you might have to purchase the Unlimited Extension for the plugin to work. Make sure to use a password on the file, and consider deleting it from your site after downloading it.
With the file downloaded, now install the same plugin on your local site, and use the plugin to import from the file. You might want to disable the indexing of any SEO plugins, as well as any email sending plugins. You yourself know best what plugins should not be running on your local development site. You might also want to cosider the compliance implications of moving data from your live site to your local site.
Start development
To start development and set up Git and GitHub, you want to navigate to the wp-content folder. You can do this by pressing the «Site folder» button in WP Local, and then going to «app → public → wp-content». In this folder, you can open your favorite code editor and terminal. In the plugins folder you can create a custom plugin, and in the themes folder you can create a custom theme. See other guides for how to develop custom themes and plugins.
Set up Git
If there is already a .git folder present from the import of your live site, go ahead and delete this. On Windows, in the File Explorer, you need to have «hidden files» shown to be able to see this folder.
To set up Git, open your favorite terminal (in the wp-content folder), and do «git init». You of course need git installed for this to work.
Next, create an appropriate .gitignore file. You want everything but your custom plugin and or theme to be ignored. Below is an example .gitignore file.
# Ignores everything
*
# Except the following directories and their contents
!plugins/
!plugins/my-plugin/
!plugins/my-plugin/**
!themes/
!themes/my-theme/
!themes/my-theme/**
# And except these top-folder items
!README.md
!.gitignore
Now, in the terminal, do «git add .», and «git commit -m «First commit».
Set up GitHub
To connect your local Git to GitHub, first, create a GitHub repository. Then, do «git remote add origin https://github.com/your-username/your-repository.git». You can now push your first commit to main by doing «git push -u origin main».
You should be able to connect this repository to your hosting provider for automatic deployment in some way, resulting in you being able to push code to your github repository from your local development environment, and having the code appear on your live site.
Getting Started Developing
Now you can start developing themes and plugins for your site locally. When you are happy with them, move your files to your live site automatically or through automatic deployment. Customizations to the site using the WordPress User Interface, like adding pages and posts and changing settings, still generally need to be done directly on your live site. Consider what belongs in your themes and plugins, and what belongs as customizations.
Legg igjen en kommentar