Home › Forums › General Issues › Theme support – pre populated fields?
Hi,
I know we can add the plugin to theme, I also know how to create custom fields but how can I add pre populated fields to theme?
Hi @Rakesh
You could hook into the theme activate hook (WP action), and use the update_field() function to update ACF values.
http://www.advancedcustomfields.com/resources/functions/update_field/
Will that work if the fields are option page fields?
I’m running into the same issue. I want to pre populate some default values for images in my theme when it is activated and need to set the image URL to the the path of an image in a specific folder.
Hi @Rakesh
2 things:
1. Yes, you can use the update_field function for an options page value
2. ACF image field needs an attachment ID, not a url to a folder
How would you go about getting an attachment ID?
I’m trying to set default images for the theme that show up in the options page when the theme is activated.
Hi @Rakesh
This bit is up to you mate.
Depends on if you are inserting them dynamically on the theme install.
Not being a hardcore WP programmer I could use a pointer in the right direction. I’m trying to accomplish this on theme install. The images are in the theme directory when it’s installed, so I’m trying have the defaults set.
My goal is to check and if the images do not have a value set then install them, otherwise leave them as-is because the admin likely has set them themself.
Hi @Rakesh
Sounds like you are creating defaults for images and falling back to default images in your theme.
Perhaps this would be better left within the theme, as in, use an if statement to check if an image value exists and if not, use the one in your theme.
To do what you wrote in the previous comment would require that you upload all default images to the WP library on theme activation. This would require a lot of code and PHP skills.
Cheers
E
The topic ‘Theme support – pre populated fields?’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.