 Please welcome Mahangu. Hi, and thank you. Okay, so first, just before I start, if I could have a show of hands, who in this room gets paid to write WordPress code? Put your hands up if you get paid to write WordPress code. Okay, so it's okay that you are here. This talk is not for you. Okay, so before we start, just a bit about me. I'm from Sri Lanka, and coming from Sri Lanka, it's a bit like Sri Lanka is told if you are really good and if you eat all your vegetables and drink all your milk, then someday you can grow up to be like Singapore. Yes, it's always like a country which we aspire to be, and I always love being in Singapore because it's such a beautiful place. And I'm really happy to be here, this WordCamp today. So my day job is being a happiness engineer, which basically means I spend most of my work day showing people how to use WordPress.com. And so if you have ever used WordPress.com and got, that's the question on live chat or email, you've spoken to somebody like me. So I've been using WordPress for a long time, and I've seen the many ways in which it has changed. And the kind of this talk also grew out of my WordPress experience. And the main part of that is that I don't write code for a living. I'm not a developer. I mess with WordPress code. I break WordPress code a lot, but I'm not a developer. And here is the main reason I say that. So in general, if you think about a software engineer, they have some programming training or experience. They get paid to write code, and they are often good at maths and sciences. And especially in this part of the world, like we do this very early on, right? We say in grade nine, if you are good at maths, you do like engineering or physics. If you're good at like, so maybe numbers, you do finance. And if you're good at nothing like me, then you do English. So for me, I have no programming training or experience. I don't get to write code, and I am not at all good at maths or hard sciences. So if you had to think of a software engineer in your mind and get a picture, here is maybe what it would look like. You think of someone like this. And if you think of a software engineer like this, then this is me, right? So that's the comparison. And that's where this word comes from. Jugaad, it's a Hindi word. Okay, now Hindi is the language I speak. The language I speak is Singhala. But I do spend a lot of time speaking at word camps in India. And so this is kind of a word I got from them. It roughly translates to hack in English. But here is the best kind of translation I can give you. And so Jugaad can range from something as complex as this to something as simple as this. And so it's basically the word hack. And so the English word we have for Jugaad is hack. And the word hack is very at the core of what WordPress is. Now does anybody know where this code is from? Does anybody recognize it? Right. It's basically from Matt's blog post in which he talks about the software that would someday become WordPress. It's not WordPress yet, but he's saying it would be awesome if we had this piece of software that could do these things. And you can see the word hackability is right there in the middle here, right? And so even before WordPress became WordPress, it was really important that it was hackable. And here's why. The first reason is that WordPress is made for everyone. It's made for everybody in this room. And it's made for everybody in the world. So WordPress is made for everyone who wants to do something with it. And so therefore you have to be able to change it easily. It has to be hackable. That's what WordPress' very core function is, to be hackable. And it's also made by everyone. So maybe misconception about WordPress is that it's made by software engineers. Yes, of course, there are software engineers who work on WordPress, but it's also made by lots of people who don't write software for a living. And that's what we're going to look at in this talk. So WordPress is hackable. And the main way in which it is hackable is via hooks. Now think of hooks like this, right? So when WordPress renders your blog, so the front page of your blog, at several, and sometimes several hundred points in that process, there are these hooks that jut out. And themes and plugins can hook into them. So the hook juts out, and a theme or plugin can hook into it and change the way WordPress does things. And especially at the time that WordPress brought in these features, it was generally really hard to change what a CMS does. It was almost impossible. You had to actually change the code of the CMS. And so WordPress kind of jumped ahead on the web, saying, hey, if you want to change, here you are. Just use these hooks. Now hooks can be split into two main parts, action and filters. It's not really important that you know exactly what an action is or what a filter is. But let's use these examples. So an action is basically WordPress saying, OK, so this action, publish underscore post, it fires whenever somebody hits the publish button on a site. So WordPress essentially asks you at that point, hey, plugins and themes, somebody just hit publish on the site, do you want me to do something? OK, so that's an action. When something happens on WordPress, you can choose to do something with your theme or plugin. And a filter is basically WordPress saying, I have this value. It's called the underscore title. And here it's the post or page title. And so WordPress very kindly asks us, I have this title with me. It's this. Do you want to change it? Right? And we say, yes, please. And so that's what we're going to do in this talk today. We're going to look at some code examples. Now, if you have not looked at programming code before, you may think it looks something like this. This is what we see in the movies. This is what we see on TV. It's things we don't understand. Only computers understand it. But actually no programming code is for humans to understand. And often it's just plain English. And especially the language that WordPress is written in is PHP, which is very close to English. So let's have a look. So now, if your first instinct is to be like, whoa, I don't understand. I just shut off and go on Instagram or something. Please stay with me. Please stay with me. Let's walk through this. Let's see how simple it can be. So there are four lines of code here. And let's walk through it now. So in the first line, that's a filter in blue, the underscore title. It's a filter. And we're saying to WordPress, every time a post title is displayed anywhere on the site, do this. And so the bit in yellow is this. And that is actually what we call a function. A function is a set of instructions. So we're telling WordPress, every time a post title is displayed anywhere on the site, do this and this. So again, every time a post title is displayed anywhere on the site, do this. So it goes like this. So let's follow what we're telling WordPress. Hey, WordPress, every time a post title is displayed anywhere, add WordCamp Singapore. I'm so sorry. Add WordCamp Singapore just before the post title. And send the modified post title back to WordPress. So every time a post title is displayed anywhere at that text, send the post title back. So we take this code and we run it. And it turns this, which is a very standard post title WordPress, into this. And so it's not that we have changed the world yet. But we have added some code which makes WordPress do something which it normally wouldn't do. And that's what WordPress hooks are. And thanks to this plugin by the way, which you can install right now, if you have a test site, Code Snippets, you don't even have to open a PHP file. You just grab the code, paste it in, hit Save Changes, and activate here. And the code runs on your site. Simple WordPress code is. But first the word of warning. Do not install Code Snippets and run these snippets on your work site. That will be a bad idea. Don't run it on your personal blog if it's live. Create a test site. So let's do it this way. So first create a test site. If you have one, that's fine. Install the Code Snippets plugin. And all the code examples I'm using today on my site, you can grab it right now if you go there. And let's see what happens. So let's walk through some more code examples. And let's see what we can make of it. So the Jougard way is basically, I used that word before, the hack way is task-based. And it uses existing resources in this sense. We aren't going to say, I want to learn PHP. This is where lots of people, including me, get stuck because you're like, oh yeah, WordPress is cool and I want to learn some code. But I have to learn PHP. PHP is this big black hole. It's a whole programming language. It's a very old programming language. And it has lots of things you can learn and learn and learn and learn and never fully learn PHP. And especially if it's not your job, it's really hard to find time to learn PHP. It's like saying, I want to learn English. It's like learning a language, which is not easy. Instead, what we're going to say is I want to learn how to. And here is the formula for doing that. Google WordPress plus what you want to do. Since it powers over 26% of the web, if you want to do something with WordPress, somebody else has done it before. And there's a guide out there. So let's, and for most things you search for, almost always your first result will be, on this side, it's a WordPress Codex site, a documentation site, and it's an excellent resource. Let's see how we can use it. So the standard WordPress login form is something which you have all seen and used, most probably. Let's see what we can do to kind of change it via hooks. Let's try and hook into the comment form and change it. So we Google WordPress plus add text to login form and we find a Codex page. We scroll down and there's a code example. So this is basically how I learned WordPress Code. I have no idea what that means, but I'm just going to copy and paste it and we'll see what happens. So let's walk through this code example again. So again you go switching off, stop, just focus. It's not difficult. So this is a filter again. It's the login message filter which we are telling WordPress. So here basically WordPress is asking us, hey, I have the login message, do you want to change it? And here we're saying yes. Every time you display the login message, do this, right? And so this we said is a function. A function is a set of instructions. Here it has only how many instructions? Just one, right? So we're saying every time you display a login message on the site WordPress, send this login message back to WordPress. The login message is WordCam Singapore. It's going to be awesome, which I think is true. So let's see what that is. We run that code and it changes this into this. And especially if you have used other CMS software, I'm not going to name them here out of respect, but if you have used them before, you know how hard it is to get them to do this. It was virtually impossible without changing the code, the actual CMS code. So this is what makes WordPress special. So let's jump straight into another example. WordPress plus add admin screen message. So maybe you want to tell all your users something, right? So we Google and we find a code example and we do our usual copy paste, right? Right. Let's look at this example. Now this is an action. So it's not that there is a value which we want WordPress to change for us. We say when you display admin notices, so like other plugins and themes can also display admin notices, we say when you do that WordPress, please do this for me. This is a function and it has one instruction. And it's a very simple instruction. It's saying output this HTML. So the CSS here is built into WordPress, these CSS classes. And here we're just saying display hello, word camp, Singapore. So we're saying WordPress, when you display admin notices at the top, do this. This is this one instruction and that is saying output this HTML. And we copy it from here, paste it into code snippets. Hit save change doesn't activate and that happens. Right. And I know it's not like we're not making like huge leaps in what we're doing, but just in four lines of code that you can add something to that main screen, which is pretty cool. Right. If you think about it. Right. So let's look at one more example. Right. So now we're getting a bit fancy. I mean what hooks are and we're getting. So we Google WordPress comment form hooks. Right. And so there are many in the comment form, but let's look at one we can take. Right. And so by now, like we are really good at this copy paste business and we just grab the code. We paste it in. Right. Because this is what we do. Right. So again here, this is an action. An action is basically he ever saying WordPress, when you display the comment form. So the comment form can be on a post. It can be on a page. It can be in any place which your team displays the comment form. Do this. Right. And this is a, as we said before, is a function. A function is a set of instructions. How many instructions are here? One. Right. And so again it's some very simple HTML. It's two strong tags. We're saying output this HTML. It's a comment form. We're trying to add the text. Are you posting, you know, like this text trying to add to the comment form. And so if you paste this code in, it changes from this to this. Right. And so if you want to add a notice asking people like to be polite human beings on the internet, this is a good hook to use for that. Right. So again, as you can see, it's not the, the, like all these books on their own, it may seem like, well, you know, like they're quite simple. Right. They're quite simple. But if you start putting them together, right, I'm sure you can already start thinking of some pretty cool things you can write just by combining these different code snippets, which we don't really understand, but we put them together. We mash them together and then we see what happens. Right. So the WordPress already has hundreds of hooks and with every new release, also there are more hooks. But the best part is that WordPress core has hooks, but every theme, every plugin you install comes with hooks of its own. So there are quite literally thousands of actions and filters that you can use if you want to do things with WordPress. Right. So, like even if you don't write WordPress code for a living, it's really useful to know what hooks are, what actions and filters are, and also how they work, simply because WordPress is the most used CMS in the world. Right. And it powers an unbelievable amount of websites. And if you work with the web at all, like just being able to know how to make a small change like this can be very, very useful. Right. And especially in this part of the world, something which we do early on, as I said, is that like in grade nine, like you are engineers, you are doctors, you are lawyers, and so on and so forth. But like, especially because of PHP and how simple it is and almost plain English, like you don't have to be a software engineer to write WordPress code. That is like, if you take only one thing away from this session, please take away that is that you don't need to have like a software engineering degree to write WordPress code, as you saw, it just happened. So, actions and filters can help you do a lot with WordPress that you would otherwise need to hire somebody else to do, which you don't need to do. If it's something simple, see if there's a hook and try and do it yourself using the code snippets plugin. So, again, WordPress is hackable. It's at the core of what WordPress is. WordPress is what it is and it has expanded to the size it is today, only because it is hackable. It is at its very core, it is hackable. And if you use this way, where you use the Jogad way of task-based learning and you use existing resources, it's not hard to get into it, right? Just Google WordPress plus what you want to do with it. So, again, WordPress is meant for everyone. It's made for every single use case in this room. It's made for every single use case in the world. But more importantly, WordPress is made by everyone. It's not just made by software engineers. It's made by all sorts of people who do all sorts of things for work. They still get involved and use WordPress code. So, WordPress is made by everyone, and that includes you. Thank you. If you have any questions, I'd be happy to answer. Yes. So, that's all the code. So, that's all the code that you copy and paste? Does it have to all go into functions.php file? Can you paste it in visual templates? Right. So, all the code examples I used today can go into functions.php file, but the code snippets plugin is easier if you don't want to create a function.php file. So, any code that goes in either the functions.php file or the code snippets plugin is loaded by WordPress. Of course, if you're creating a theme of your own, of course, you can put it in your own template files as well. That's up to you, but anything you paste in the code snippets extension, sorry, in the plugin, or in the functions.php file is automatically run by WordPress. Yes. Can I just change it? I was keeping it out. Right. On the very first slide, is it? Well, I was keeping it there, or I can change it everything I want. Right. Right. Okay, so that's a good question. Okay, so the short answer, right? Because this is... I'll be happy to speak to you after as well, but the... So, basically the short answer is that this tells WordPress at which point it should do this, right? Because if you have lots of actions and filters, other plugins and themes can also do things at the same point with the post title. So, like, if you want, like, some other themes are going to run first. So, the... Essentially, this number tells WordPress when to run it, at which point. Is it first? Is it after the plugins? So, it's a little more complicated, but essentially, the gist is that it's a priority WordPress gives to this... to... join instruction here at which point. At which point should WordPress run it? So, like, sometimes if you run this, maybe the title is in fact empty, empty because something else has changed it. And so then you would bump this up and say, okay, so give me the title first and I'll change it, and then you can give it to other plugins and themes and so on. So, if I have no idea what is the priority and so I'll just give it back where it has been. Yes. Is there any more questions? Okay, if not, thank you so much.