Home › Forums › General Issues › Add a subject line to Email mailto? › Reply To: Add a subject line to Email mailto?
I use a text field. I have built additions to text fields for ACF.
First I add a setting to all text fields
add_action('acf/render_field_settings/type=text', 'validate_text_as_href_setting');
function validate_text_as_href_setting($field) {
// this addes a setting to text fields
// setting it to true will require that the content of the fields
// meets requirements to be used as a link href value
$args = array(
'label' => 'Validate as HREF',
'instructions' => 'Requires a valid href attribute. This includes values starting with: http://, https://, ftp://, mailto:, tel:, sms: /, and #',
'type' => 'true_false',
'name' => 'validate_href',
'ui' => 1,
'class' => ''
);
acf_render_field_setting($field, $args);
}
The I have a validation filter for all text fields
add_action('acf/validate_value/type=text', 'validate_text_as_href', 10, 4);
function validate_text_as_href($valid, $value, $field, $input) {
// if the setting created by validate_text_as_href_setting
// is true than this filter will text input to ensure it can
// be used in as a link href value
// this allows links starting with
// / (site root relative), http://, https://, ftp://, # (anchor), mailto:, tel:
if (!$valid) {
return $valid;
}
if (isset($field['validate_href']) && $field['validate_href'] && !empty($value)) {
if (!preg_match('%^(https?\://|ftp\://|/|#|mailto\:|sms\:|tel\:)%i', $value)) {
$valid = 'Enter a Valid HREF Value';
}
}
return $valid;
}
I use another text field for the link text.
then, of course there is the code to add to show the link
<a href="<?php the_field('my_link_field"); ?>"><?php the_field('my_link_text_field'); ?></a>
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.