• I want to display a certain og image if a certain category is chosen for a post. I do it like this:

    if (has_category(1)) { $image = pathtoimage; }

    then I would use that variable to display the og:image through my html

    Now the problem is that this only works whenever there are more then one category selected then slug id 1 so whenever category slug 1 is ONLY selected, the og:image wont show. Am I using has_category wrong?

    Thanks a ton

Viewing 1 replies (of 1 total)
  • You should pass the name, term id (must be an int) or slug of the category, or an array of those values, to has_category().

    If you want to show the go:image tag for the category that has ID = 1, then your code should do the trick. The problem may be associated with the way and place in the code where you are using the value of the $image variable.

    Where is your code being used?
    What template?
    Is it inside the loop?
    Where is the value of the $image variable being used?

Viewing 1 replies (of 1 total)
  • The topic ‘Display og:image if category selected’ is closed to new replies.