Adding Custom Fields to a single blog post

Updated on May 15, 2019

To be able to add custom fields to a single blog post, you need install the plugin Advanced Custom Fields PRO. It’s bundled with Jupiter X and can be installed via Jupiter X > Control Panel > Plugins as described in this article.
If you want to add some link or text to post meta section, at first you need create a field to show it in the backend editor of your post like a setting where you’ll be able to insert your text, link or other field type.


Note:
 Another plugin that can be used to create custom fields is JetEngine which is also bundled in Jupiter X and can be installed via Jupiter X > Control Panel > Plugins.
How to add custom fields using this plugin, refer to the 
official documentation and also watch their video tutorial.

The Advanced Custom Fields plugin makes it very easy to add custom fields to a Post, please follow the steps below.

1. From the Custom Fields admin screen, click the Add New button to create a new field group.

2. Add the fields you would like to see when editing a Post. You can select any field type: text, link, image, button, etc. See more here.
For example we want to add an author email in the meta section. We select Email as Field Type. Configure other settings for your needs.


3.
 Under Location, select one of the Post related rule types (such as Post Type) and then select the corresponding value to show this field group. In our case we select Post.


Note:
 Leave the Style setting as ‘Standard’ if you wish for the field group to appear within a WP Postbox.

4. Publish the changes.

Now you can edit a post and you’ll see the option to add an email address.

Don’t forget to update the post after making changes.

Now to be able to show this email address on a single post page in post meta section, you need install the child theme and edit functions.php file.
It can be edited via FTP in wp-content/themes/jupiterx-child/functions.php or via WP Dashboard in Appearance > Editor.

Add this code in the functions.php file:

add_action( 'jupiterx_post_header_after_markup', function() {
    echo the_field('email');
} );


Change email to your custom field name that can be found in the Custom Fields settings:

If you want to add some text to beside the email address, the code should be like this:

add_action( 'jupiterx_post_header_after_markup', function() {
    echo 'Author email: ';
    echo the_field('email');
} );

This way the custom field will be added under the post meta section:

Note: You can use the following suffixes with the markup-ids:
// _after_markup
// _before_markup
// _append_markup
// _prepend_markup
For example, if you want to show a custom field before featured image on a post, you can use this code:

add_action( 'jupiterx_post_image_before_markup', function() {
    echo 'Author email: ';
    echo the_field('email');
} );

You can look for other markups of a single blog post in wp-content/themes/jupiter/lib/templates/fragments/post-single.php


Note: To get more details on ACF plugin usage, refer to their documentation.

Did this answer your question?