I have found it useful in a custom post type to use render_callback if you choose to have more than one template. For example, I have different templates for the single post view and a grid view of all of my posts. The render_callback function can pick which template to use.
Templates, like template parts, let you have imaginably chunks of code. Some like template parts because they can look at a theme folder and immediately know what file is doing what to know where to make changes (as long as the template parts are named well that is). Callback functions can be harder to track down.
Going back to the other commenters example I could also create one render_template and then do multiple things in that single template based on the ACF fields. Or I can do the same thing in a single callback function. The solution of making a choice and loading different templates instead keeps code more manageable and allows for easier extension. This could also be accomplished by creating additional functions that can be called from the main callback function.
I generally let my goal dictate what style I’d use in each case. But I do like using templates for the reason I mentioned. I name them well and I can look at the template files and know which one to edit. I try to do this with functions and filters I create, but generally I end up with large files that are doing multiple things and it becomes more difficult to find the callback function I need to edit. Given this I would likely go with a template as my first choice.
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users