 Welcome back to the channel Today we are going to first make our code a little bit better make it a little more full proof, make it more readable but now protect it basically and what we are going to do is use namespaces I want to give you a reason why you should use namespaces So I am going to introduce a file and I will call it extension.php I am going to open a new function and I am going to paste a similar name in our function here and all it does is just say echo hello I will just properly wrap this here and save now if we were to if we were to require this file in our project and come here so we say require once and then of course close this off with a semicolon this extension.php file and save it we come back to our plugins and actually activate our training post we will see that we have a feto error and it says you cannot redeclare this same name now this happens a lot and in most cases with so many plugins that you might install on your WordPress however there is a trick and with the modernization of PHP that saves us this headache and that's what we call namespaces so in a simple way namespaces are basically like how they create a platform for you to use for example if I have a folder if I have a folder in my documents called adobe and I have this one which is called personal tutor and both files actually have inside them a file that's called maybe called file.txt so we have file.txt in adobe and we have file.txt in personal tutor however in the different folders or directories we can have the same file name and that's allowed on the system and those files can coexist and they can function differently even with similar names so namespaces sort of give us that advantage in that they will allow us to run the same function names across different plugins and we won't have errors like this one now namespaces do that by default that's their primary reason but they also allow us to reduce the length of a function names for example I wouldn't have to use a tpw if I would be able to reduce this and make it a simple self post views function equally I would do the same thing in here now the way we introduce namespaces is that we come it's always the first line that we have and say namespace and I am going to give this umchi guy as the first word that I'll use you can use one word or two words and use a pakwad slash and then you can use a tpw for example this is the name of what I've decided to call a trending post widget can actually be what we use here but we would use underscores instead of the different dashes that we are using here so if we use an underscore that would be a proper namespace now the next thing that we do here is that we allow ourselves to actually have whenever we are calling these different functions for example we're using the self post here I'll just make this also self post to make it simple whenever we are calling this function here we have to introduce this variable this global variable which is called namespace then we append to it and also add a forward slash to allow that to work so if we come back here I'll refresh this and then reload our trending posts you'll actually see that we don't have any errors coming in in our plugin so that means both of our functions are working together here and they are coexisting so that is when we can use namespaces and that allows us to have our code beautifully added in so going forward I'll be using namespaces to allow us to use shorter function names but also to allow to remove any future clashes that we might have in our plugin and other plugins that we might add that basically use the same function names so thank you for watching if you enjoyed this video it was really short but just to show you how we're going to protect ourselves and how we're going to make this a little better so thank you for watching if you like the video please give it a thumbs up and if you like to see more please subscribe to the channel and hit that bell so that you can be notified about what's coming up thank you for watching and happy coding