Notice: These forums are now retired and closed. For active support, please Submit a Ticket or visit our official WordPress.org community pages.
Kadence Theme | Kadence Blocks | Starter Templates | WooCommerce Email Designer | Ascend | Virtue | Pinnacle

How can I add some custom fields that will appear on the post single page?

Home / Forums / Kadence Theme / How can I add some custom fields that will appear on the post single page?

This topic is: Resolved
[Resolved]
Posted in: Kadence Theme
May 13, 2021 at 6:50 am

I’ve added a couple of custom fields using the Advanced Custom Fields plugin, now I want to display the values of these fields on the post/single page. For example, when I click on a post an navigate to it, I want to see the full post content, then add a new section with these custom fields.

Post structure:
– Categories
– Title
– Metadata (author, dates, etc)
– Post Content
– Tags
this is where I want the values from my custom fields to appear.

Important, I’m not trying to make or display data entry fields, I just want to display the values that I entered in the custom fields when editing the posts. I know how to write all the PHP and markup to do this, but I don’t know how to integrate that with the Kadence Theme or WordPress in general.

I’m using a child theme to customize a few things so my first idea was to duplicate the single.php from the Kadence them and make a version with the extra content that I want. That is proving difficult, because it appears that the Kadence Theme is built in such a way that the code is abstracted and all over the place…

The second I idea I had was to use filters to append the custom field values to the content. I’m having trouble with this too. For example, when I use the code snippet below, the result is broken. The text inside the <a> tag is in the correct place, but the result of the_field('acf_library_url') gets prepended to the start of the content instead of where it should be (in the href attribute of the <a> tag. I’ve tried this with other values as well, such as the_title(), just to confirm that this is not caused by the ACF plugin.

My filter attempt:

function add_fields_to_content($content)
{
$URL = the_field('acf_library_url');
$link = '<a href="' . $URL . '">Link</a>';
return $link . $content;
}
add_filter('the_content', 'add_fields_to_content');

So my main question is this: Can you suggest a way to add the values from custom fields to posts on my site?

  • The forum ‘Kadence Theme’ is closed to new topics and replies.