From the course: WordPress: Action and Filter Hooks

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Conditionals and context

Conditionals and context - WordPress Tutorial

From the course: WordPress: Action and Filter Hooks

Start my 1-month free trial

Conditionals and context

- [Instructor] When you're trying to accomplish something with code odds are you want it to happen within a specific context. For instance, maybe you only want your code to execute on posts not pages or within the admin area and not on the front end of the site. Sometimes the hook itself defines the context, such as the login header URL we've looked at. That hook is only ever run in a file called wp.login and is responsible for the output of this login screen. Other times a hook may come into play across multiple template files, such as the content which filters and outputs content for the current post. WordPress gives us conditional tags so that we can get really specific about where we run our code. Conditionals always return a value of either true or false. As an example, here's the is_admin conditional. It only returns true if a user is in the admin area of the site. This is a conditional you could use if you only…

Contents