plugins - Advanced Custom Fields into functions.php

admin2025-01-07  4

I'm trying to include a few custom fields I've created in my functions.php file so they're native to the theme I'm working on. However they're not showing up on the edit screens of the posts I've set them to.

I've included the acf plugin in my theme by using this code in my functions.php: include_once('advanced-custom-fields/acf.php');

I also exported the fields to php and copy and pasted the code in the functions.php of my theme. Can anyone tell me what I'm doing wrong?

I'm trying to include a few custom fields I've created in my functions.php file so they're native to the theme I'm working on. However they're not showing up on the edit screens of the posts I've set them to.

I've included the acf plugin in my theme by using this code in my functions.php: include_once('advanced-custom-fields/acf.php');

I also exported the fields to php and copy and pasted the code in the functions.php of my theme. Can anyone tell me what I'm doing wrong?

Share Improve this question asked Jan 22, 2017 at 15:01 JerroldJerrold 563 bronze badges 0
Add a comment  | 

2 Answers 2

Reset to default 0

Check that ACF included in your theme, if not than include acf. Try to use following code:

if( !class_exists('Acf') )
    include_once get_stylesheet_directory_uri() . '/advanced-custom-fields/acf.php' );

Have you added the custom field into a post?

In my experience, using the custom field in functions.php, plugins, templates, or whatever doesn't put the field as an option in any post. Adding the field manually into any post WILL make it available to any post after that.

And you don't need ACF (Advanced Custom Fields plugin) to use custom fields, unless you want all the fancy options they supply. All you have to do is create a custom field, then start accessing it via appropriate calls to postmeta.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736255595a295.html

最新回复(0)