Skip to content

Instantly share code, notes, and snippets.

@morgyface
Last active July 12, 2016 08:32
Show Gist options
  • Select an option

  • Save morgyface/720f760c46fcbf3a5617ee6ae459ba61 to your computer and use it in GitHub Desktop.

Select an option

Save morgyface/720f760c46fcbf3a5617ee6ae459ba61 to your computer and use it in GitHub Desktop.
WordPress | If no featured image show a generic image
@morgyface
Copy link
Author

No image, no problem muthalicker

Pretty basic stuff but nice to have on file. Basically we check to see if the current post has a featured image. If it does then great, we grab the ID of the image and then the source so we can echo the URL. If not, then we grab a generic image from the active theme's images folder.

This could go in single.php or be inside a get_posts loop within another template.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment