Forum Replies Created

  • Thanks! Super helpful 🙂

    I’ve slightly updated the code and I’ll leave it here in case it helps anyone googling for stuff like adding two ACF fields together, dynamic link from ACF fields e.t.c

    function buy_card_shortcode() {
    	global $post;
        $card_id = get_field('card_id');
    	$card_name = preg_replace('/\s+/', '+', get_field('card_name'));
        $output = '<a class="buy-card" href="'.$card_id. '+' .$card_name.'">eBay</a>';
        return $output;
    add_shortcode( 'buy_card', 'buy_card_shortcode' );

    This code gets the post id, then gets one text field, then gets another and replaces all spaces and whitespace in that second text field with the + symbol.

    It then prints a link to ebay with both fields added together, with the plus symbol in the middle because that’s how eBay handles spaces.

    Then you just put the shortcode [buy_card] into any post and it’ll print a link saying “eBay” that links to a search for that card (or whatever you use) on eBay. You can then add an affiliate link on the text, something I’ll eventually do.

    There is a CSS class called “buy-card” that you can then style the link with.

Viewing 1 post (of 1 total)