Skip to content

Instantly share code, notes, and snippets.

@daviddarnes
Last active October 22, 2020 17:30
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save daviddarnes/5563740 to your computer and use it in GitHub Desktop.
Save daviddarnes/5563740 to your computer and use it in GitHub Desktop.
Custom Image field for Anchor CMS themes.
<div class="bg-header"
<?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
?>
style="background: url('<?php echo $image; // Echo the result, which in this case is the url of the image ?>')"
<?php
endif; // End of custom field
?>
><!-- Contents of the header div -->
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment