Home Forums General Issues Theme support – pre populated fields?


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.

  • 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

  • @elliot

    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.

  • @elliot,

    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.


Viewing 8 posts - 1 through 8 (of 8 total)

The topic ‘Theme support – pre populated fields?’ is closed to new replies.