Home Forums Front-end Issues How can I use Code Snippets plugin with ACF?


How can I use Code Snippets plugin with ACF?

  • Hello, PHP noob here.

    I use the Code Snippets plugin to edit my code. I’m trying to add a link to single product page, and using Code Snippets with ACF to do so. Using ACF Documentation example ‘Link’ code, I wrote the following into my Code Snippets plugin:

    function product_datasheet_below_summary() { ?>
    	$link = get_field('datasheet');
    if( $link ): 
    	$link_url = $link['url'];
    	$link_title = $link['title'];
    	$link_target = $link['target'] ? $link['target'] : '_self';
    	<a class="button" href="<?php echo esc_url($link_url); ?>" target="<?php echo esc_attr($link_target); ?>"><?php echo esc_html($link_title); ?></a>
    add_action( 'ocean_after_single_product_meta', 'product_datasheet_below_summary', 5 );

    This doesn’t work, it simply prints:

    $link = get_field(‘datasheet’); if( $link ): $link_url = $link[‘url’]; $link_title = $link[‘title’]; $link_target = $link[‘target’] ? $link[‘target’] : ‘_self’; ?>

    onto the page, followed by a generic square button link,

    What am I doing wrong here? Thanks very much for your help.

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.