• Resolved jathang

    (@jathang)


    I’m trying to add external product links within my theme’s template files. The do_shortcode function works on the basic ‘internal’ link, so the following code works just fine:

    echo do_shortcode( '[product_link]' );

    But I just can’t seem to get the external attribute to work:

    echo do_shortcode( '[product_link external=true]' );

    I’ve tried it with or without quotes, and putting the attribute value into a variable, but it still doesn’t show up. Any ideas?

    Perhaps I should avoid shortcodes altogether, and just pull the URL from the custom field (in which case, could anyone help me with the correct name)?

    I can’t put a link up, as I’m testing it on localhost for now.

    https://www.ads-software.com/plugins/etsy-importer/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Michael Beckwith

    (@tw2113)

    The BenchPresser

    What’s the resulting url for your attempt with the external version?

    I believe the meta key for the url is _etsy_product_url based on checking the code quick.

    Thread Starter jathang

    (@jathang)

    Thanks for getting back to me, Michael. For the time being, I’ve hacked the plugin to suit my needs. The do_shortcode with external attribute does actually work, but not in the way I want it to. I can get a single product’s external link to show up, with the following:

    echo do_shortcode( '[product_link id=1 external=true]' );

    But ideally I want it to change all links to point externally. Ideally – to change the permalink url on my products page. Is there any way to incorporate the shortcode within these template tags (using a Twenty Fifteen child template of ‘contents.php’)?

    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>

    I’ve tried pulling in the _etsy_product_url meta key, but with no luck.

    Thread Starter jathang

    (@jathang)

    OK – I’ve managed to get the _etsy_product_url meta to work. Here’s what I use in my template files:

    echo get_post_meta( get_the_ID(), '_etsy_product_url', true );

    I’ll mark this topic as resolved – although it’s moved away from the original thread title somewhat ??

    Thread Starter jathang

    (@jathang)

    This is the full chunk of code to replace the_permalink section above:

    <h2><a href="<?php echo get_post_meta( get_the_ID(), '_etsy_product_url', true ); ?>"><?php the_title(); ?></a></h2>

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    You’d need to replace the_permalink() with an echo’ing of the exteranl link meta field.

    <h2><a href="<?php echo get_post_meta( get_the_ID(), '_etsy_product_url', true ); ?>"><?php the_title(); ?></a></h2>
    Michael Beckwith

    (@tw2113)

    The BenchPresser

    I didn’t refresh before I replied. We came to the same conclusion though ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Getting shortcode in template files to work’ is closed to new replies.