There’s different code you can use to display the value of your custom field keys depending on different situations.
The code may vary depending on which theme you’re using and can also be different if you’re using a custom fields plugin like Advanced Custom Fields which is commonly referred to as ACF.
In this post i’ll provide 6 different code snippets where some work with:
- The ACF plugin
- The Genesis theme framework
- Any theme
- All code should be pasted at the end of your child themes functions.php file using a code editor like Notepad++
- All code snippets include the loop_start hook which works with any theme as its a WordPress core hook. You can change this to any theme specific hook if needed.
- All snippets also include the is_single() or is_singular(‘post’) conditional tag for testing purposes which only display your custom fields content (value) on single posts. These 2 conditional tags can also be changed.
- All examples also use the custom_field_name (key) which you replace with the name of your custom field.