I have been asked to help with my church’s website. It uses ACF for the staff biography page, via flexible content. We want to establish bookmarks for each flexible content row, so that we can link to that staff member from other pages and posts within the site.
For example, I have Pastor Steve, Reverend Marshall and Sister Claire. When each of these people are mentioned in other pages and posts on the site, I’d like to have it link to the Staff page, at a bookmark for that person like http://www.church.org/staff#PastorSteve.
I’m fine with having to establish the link manually, it’s establishing the bookmark that I cannot figure out and there does not appear to be an add-on for creating these bookmarks. Am I missing something? How can this be accomplished?
You need to edit the them file that output the flex field. In this template you need to find whatever is wrapping each layout and add an ID to it.
But without knowing how the layout is output in your template or what fields are available in the ACF field group I wouldn’t be able to give more specific help.
The hope was that ACF had something built in for bookmarks. Modifying templates requires more advanced knowledge and adds the risk of breaking other things, plus a template update (for non-custom themes) would lose the changes. The suggestion made by John only accounts for one section of the page, not multiple sections as a result of flexible content. – Thank you for the input, though.
I ended up creating a text field in my flexible content, so that I could define what would be used for the bookmark for each person’s content. I then modified the template to pull the text field’s content and apply it to the flexible content loop ID property. Fortunately our theme and templates are custom, so I don’t have to worry about losing changes in an update.
<?php $staffname = get_sub_field('name'); $staffbiog = get_sub_field('bio'); $staffmark = '"' . get_sub_field('bookmark') . '"'; ?> <section class="block flex_detail" id=<?php echo $staffmark; ?>> <article class="flexcon"> <div class="flexentry"> <header> <h4><?php echo $staffname; ?></h4> </header> <?php echo $staffbiog; ?> </div> </article> </section>
Most themes using ACF are custom and don’t get updated. There is nothing built in to ACF that to modify the content and markup of your a site. There are a few themes that use ACF, but most developers that use ACF are building custom themes.
The solution you have is what I was beginning to suggesting, but without the details I was asking for I could only go so far.
The only difference in what you did and what I would have suggested is that I probably would have used an existing field
$staffname = get_sub_field('name'); $id = preg_replace('/[^a-z0-9]+/' '-', strtolower($staffname));
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
Helping others is a great way to earn karma, gain badges and help ACF development!
🙋♂️ We are researching for our upcoming website redesign and would love to showcase some brands/agencies of popular or well known websites that use ACF.— Advanced Custom Fields (@wp_acf) October 11, 2019
If you have worked on, or know of any websites that would suit, please comment below.#WordPress
© 2019 Advanced Custom Fields. Subscribe