Home › Forums › General Issues › Extend default ACF Link field
Hello,
I would like to extend default link field by adding one more text input like link text. Then be able to assign the value within insert/edit link window and use it like so: $link['sr_only'];
I have been searching in the web for extending fields but I think that I am not going in the right direction. Is there any possibility to achieve this?
Will appreciate any help from you.
ACF uses WPs built in link field that is used when editing content. To change the ACF field you would need to change WP component. I don’t think anyone has figured out how to do this.
This seems to be the answer across multiple topic in acf forums ;(
Say we want to add an ID – its easy to attach a field
into the link dialog box. But the data isn’t being saved
with acf.
$('#link-options').append(
<div>
<div className=”flex flex-row”>
<label htmlFor=”wpse_link_class col-6″>
<span>Button Type</span>
<select name=”wpse-link-class” id=”wpse_link_class”>
<option value=”normal”>normal</option>
<option value=”btn btn-yellow”>Yellow button</option>
<option value=”btn btn-yellow btn-lg”>Yellow button (big)</option>
<option value=”btn btn-outline”>Outline button</option>
<option value=”btn btn-outline btn-lg”>Outline button (big)</option>
</select>
</label>
</div>
<label for=”sgx_custom_link_id”>
<span>Link ID</span>
<input type=”text” name=”sgx_custom_link_id” id=”sgx_custom_link_id” />
</label>
</div>
`);
wpLink.getAttrs = function() {
wpLink.correctURL();
return {
class: $( ‘#wpse_link_class’ ).val(),
href: $.trim( $( ‘#wp-link-url’ ).val() ),
target: $( ‘#wp-link-target’ ).prop( ‘checked’ ) ? ‘_blank’ : ”,
id: $( ‘#sgx_custom_link_id’ ).val() // this doesn’t work.
};
}`
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 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.