Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
A simple way of extending the functionality of a WordPress site is by adding plugins. And most plugins work pretty much out of the box. But there are many great plugins out there that either require you to make changes to your theme or that allow you to use them in more advanced ways by including their functions into your theme. This is a great use for child themes and done right, it can be both simple and effective. To give you an example of how this works, let's add a list of related posts at the bottom of our single post view using the Yet Another Related Posts Plugin and a custom function.
The Yet Another Related Posts Plugin, or YARPP as it's called, is a great plug-in that adds a list of related posts wherever you want it in your site. The great thing about the plugin is it actually reads your content and figures out what posts relate to what other posts. So that when people read a post on your site at the bottom or at the top of the site, they find lists of other related posts they're probably going to be interested in. That keeps them on your site longer and it also makes for a better experience for the people that visit your site.
First we need to add the plugin to our sites. So I'll go to the Dashboard, go to Plugins > Add New, and here I'll simply search for YARPP. I find it down here, Yet Another Related Posts Plugin, I'll install it, activate it, and then I get a flag that says I've installed it and then I need to go configure it. So I'll directly to the Related Posts settings page. Now if you're using BitNami like I am, you may get this warning message at the very top here that says that things aren't working the way they're supposed to in the database.
This is an issue that's related to how BitNami sets up a database. And you're very unlikely to see this on a website that lives on a web server on the web. So just ignore it and move on. When you install YARPP, you're most likely going to see that Automatically Display Related Posts is activated by default. If it is, and you go to a single post, scroll down to the bottom, you'll find that it either says no related posts or that there is a list of related posts at the bottom of your posts.
This is one that's auto inserted, and it's always inserted before this content at the bottom of each post. But what if you want to place it somewhere else? Let's say, I want to have this list appear beneath the meta content and in place of the standard navigation that points you to the previous and next post, because I think that navigation is silly. In that case, I need to turn off the automatic insert and insert the function manually instead. And I can do that, because YARPP allows me to do it. So I'll go back to the settings for YARPP.
Turn off Automatically Display Related Posts and then hover my mouse over this more tag and it tells me that I can use a function called related_posts to display the related posts in my template file. To get that to work, I first have to go to Twenty Twelve, find the template I want to edit, in this case single.php, copy it into my child theme, open the child theme, single.php file in my code editor, and then find the content I want to replace, which is right here, nav-single, and also add in the content I want to replace it with.
First, I'm going to remove this content I don't want. This is the navigation that points on the previous and next post and I think that's kind of silly. So I'm going to take it out and in its place I'm going to place that function that came with YARPP. So I'll put in PHP delimiters and then I'll put in the function. I'll save the template and reload my single post. And now you see that in place of the navigation that was here previously, we now see no related posts.
I also see that I forgot to deactivate the automatic insert. So I'll go back to related posts, make sure it's unchecked, click Save Changes, reload my single posts and now you see no related posts appears here. But there is a caveat here. The function Related Posts is associated with the plugin, so what happens if I deactivate the plugin? I'll go into Plugins > Installed Plugins and deactivate Yet Another Related Posts.
And now when I reload the single post here, you'll see something very strange happen. The post will generate, but then it terminate at the bottom here, before it's finished. That's because in my template file, I'm calling a function that no longer exists. So here's the rule of thumb, if you ever add a function from a plugin, you must wrap it in a conditional statement that tests to see if that function exists. The function you're going to wrap in is not surprisingly called function_exists.
So we'll simply ask, if function_exists, give the name of the function, and then we say, as long as the function exists due the following. In this case, run the function and then end the conditional statement, save the template file and reload the page, and now the page works even though the function did not kick in.
And if I go back to WordPress, reactivate Yet Another Related Posts Plugin and reload the page again, the function reappears. If you use plugins in your site, I guarantee you'll come across ones that require you to add functions or other elements to your template files. Using a child theme and wrapping these plugin functions and conditional function_exists tags ensures that you get the full use out of your plugin, that if the plugin breaks or gets deactivated, or uninstalled, it doesn't break your site.
And that if something disastrous happens when you install the new function, all you have to do is remove the template file from your child name and everything goes back to normal again.
Get unlimited access to all courses for just $25/month.Become a member
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.