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:

    I installed the (free) plugin “Code Snippets” on my site:

    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


    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');