Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Start a free Basic trial
to watch this video
In this video, we go over some of the different ways to edit PHP files on live and local WordPress sites.
Links Referenced
-
0:00
When it comes to editing PHP files in WordPress,
-
0:03
there are two ways we can go about it.
-
0:06
It all depends on where and how we're running our WordPress site.
-
0:10
The two examples we'll look at here are locally editing files and
-
0:15
remotely editing files, or editing files live on a server.
-
0:19
We have two example sites here.
-
0:21
One, phpforwordpress.dev, I have running locally using software desktop server.
-
0:28
The other one, wptreehouse.com/toursofnature,
-
0:33
we have running on an actual, live server.
-
0:36
Let's take a look at how we would edit our local files first.
-
0:41
When we have a local server installed, it's likely that inside of our
-
0:45
applications folder we'll have a mamp or a xampp folder set up.
-
0:51
Inside of that folder, we'll eventually find a folder called htdocs or
-
0:57
publichtml or something similar to that.
-
0:59
It depends on what type server configuration you have set up, and
-
1:04
we have several videos on Treehouse about setting up local environments for
-
1:10
running WordPress.
-
1:12
Once you figure out where your local server folder is, you could find your site
-
1:17
and then navigate in and find all of the local WordPress files.
-
1:21
And let's say we were going to make some edits to our theme file here.
-
1:27
We're running a child theme, and let's say we wanted to make edits to our header.php.
-
1:32
What we would need to do is open this up inside of a code editor.
-
1:38
For this example, we're using Sublime Text 2,
-
1:41
which is a great environment for working with WordPress.
-
1:45
Once we open up this file, we should see all of the code here and
-
1:50
we could come in and make our changes.
-
1:54
Let's just add in some test code here to see if our changes take effect.
-
2:00
Once we click save, we should be able to come over,
-
2:03
view our site again, refresh it, and see that these changes take place.
-
2:09
One of the great things about coding locally
-
2:12
is that you can undo mistakes if you make them.
-
2:16
Let's go ahead and close this now and
-
2:18
look at how we would make a similar change on a live site.
-
2:23
When it comes to editing live sites,
-
2:25
there's two ways we can go about making these changes to php files.
-
2:30
Both of them require FTPing in to our site.
-
2:35
Once we have used ftp software, like CyberDuck, for example,
-
2:39
to connect to our site, we can come in, find the file that we want to change.
-
2:47
And then do one of two things.
-
2:50
We could edit it directly from the server,
-
2:55
where we will edit the file,
-
2:58
make the changes that we want, save them, and
-
3:03
come back and refresh our site, and see those changes.
-
3:13
Or, we could download this file to our computer.
-
3:22
And then find that file locally, make the changes that we want.
-
3:30
However, when we refresh our site, we will see that those changes have not yet
-
3:34
been applied.
-
3:35
The reason is, we then need to go and
-
3:38
re-upload that new file that we just changed back to our server.
-
3:47
We'll overwrite the existing file.
-
3:53
And then we should see the changes made.
-
3:56
The first approach is often referred to live editing or cowboy coding and
-
4:01
can be a little bit dangerous, because once the change is made on the server,
-
4:05
you might not have an option to undo it.
-
4:09
Making a backup of the file and
-
4:10
making the changes locally, and then pushing it live, is a little bit safer.
-
4:17
Let's go back to our local file, remove the code we added,
-
4:22
save it, and then re-upload our file again.
-
4:33
Seeing that the changes are made.
-
4:36
This is a little bit safer.
-
4:38
However, the best way to go about it is to have a local copy of your site running
-
4:45
on a local server so you can download the whole site, make the changes locally,
-
4:50
test and make sure that everything works, and then re-upload your content.
-
4:55
I encourage you to check out on our local development or
-
4:58
WordPress workflow courses for more information about how to do this.
-
5:03
However, we're going to go on from here now that we've looked at how to edit
-
5:07
PHP files, and start looking at how to code some basic PHP.
You need to sign up for Treehouse in order to download course files.
Sign up