Home › Forums › Bug Reports › Broken Page Link when layered on top of text › Reply To: Broken Page Link when layered on top of text
Following the example in this issue:
https://wordpress.stackexchange.com/questions/291524/inserting-html-tag-with-acf-into-shortcode
I installed the (free) plugin “Code Snippets” on my WordPress.com site:
https://wordpress.org/plugins/code-snippets/
I created a new snippet.
The code snippet below creates a new shortcode called “[my_special_link]” that takes two parameters:
1. acf_link_field : the ACF field name you want to call on (assuming it’s a link type field)
2. text_value : the text you want to hyperlink on top of
[my_special_link acf_link_field="example_page_link" text_value="Whatever I want"]
This adds the text “Whatever I want” to the page and hyperlinks it to the ACF field link at field=example_page_link.
You could adapt this code to chain together however many ACF fields you wanted.
. . .
Title: ACF Link Field PLUS Text Value
Code:
<?php
function my_shortcode( $atts ) {
$atts = shortcode_atts( array(
'acf_link_field' => '', // Default value.
'text_value' => '', // Default value.
), $atts );
$output = '[acf field=' . $atts['acf_link_field'] . ']' ;
$output = do_shortcode( $output );
$output = '<a href="' . $output . '">' . $atts['text_value'] . '</a>';
return $output;
}
add_shortcode('my_special_link', 'my_shortcode');
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.