I am trying to conditionally change a link based on what page a user is on, but I am having trouble finding the correct code to perform the action.
Here is what I want to do (In English to explain the code)
If a user is not logged-in and on a page that is either keyword or a child of keyword (for example, domain.net/keyword/pricing or domain.net/keyword/about or simply domain.net/keyword)
Then Show X
If user is not logged in and on any other page besides those mentioned above
Then Show Y
If user is logged in
Then Don’t do anything
I’ve tried multiple conditionals and read the wordpress codex, but can’t figure this one out. I am novice php user, so I wouldn’t be surprised if the answer was quite simple.
I appreciate the help in advance!
If it is about child post types* or taxonomies**:
It could be that you have to check the
if
against0 !== $post_/taxonomy_object
, but it should work close to shown above.*) Post types are the built in ones like post and page, or custom ones like custom post types.
**) Taxonomies are the built in ones like category (hierarchical), tags (non-hierarchical), post_format, etc, or your custom ones like custom taxonomies.
I’m assuming you are referring to pages and child pages. If so, you can use this in your template within the loop: