Skip to content

Instantly share code, notes, and snippets.

@bugsysop
Forked from daviddarnes/Anchor Custom Article Field
Last active December 17, 2015 18:29
Show Gist options
  • Save bugsysop/5653183 to your computer and use it in GitHub Desktop.
Save bugsysop/5653183 to your computer and use it in GitHub Desktop.
For outputting a custom field marked with 'image' in the database within an article.
<?php
/*
This is to show a custom field from an article.
It will need to be created in the metadata section before it can be used in the post edit area.
In this case the custom field will need to be called 'image' and be set as an image custom field in the dropdown for type.
*/
$image = article_custom_field('image'); // Applying a variable to the custom field, so it can be reused with ease
if ( !empty($image) ) : // Check if the field is empty, if it is the process stops here
?>
<figure>
<img src="<?php echo $image; // Echo the result, which in this case is the url of the image ?>" width="440" alt="<?php echo article_title(); ?>" />
</figure>
<?php
endif; // End of custom field
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment