• Resolved Daven

    (@daven)


    I have a bit of coding I need to be able to edit each time.

    <a href="https://www.amazon.com/gp/product/ISBN10 HERE?ie=UTF8&tag=davensjournal-20&linkCode=as2&camp=1789&creative=390957&creativeASIN=ISBN10 HERE" style="float:left;">[abp:ISBN10 HERE]</a>

    This is a callback to another plugin that will let me display the cover of the book I’m reviewing. I have three places I have to edit the ISBN, and if Code Snippet puts it in as a shortcode, I can’t edit those places.

    So how do I get the plugin to drop the whole code strand into the post rather than the shortcode?

Viewing 1 replies (of 1 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    Hi Daven,

    In this situation you might be best off defining your own shortcode as a Functions snippet:

    $shortcode_tag = 'amazon_link';
    
    add_shortcode( $shortcode_tag, function ( $atts ) use ( $shortcode_tag ) {
    	$atts = shortcode_atts(
    		array(
    			'isbn' => '',
    		),
    		$atts,
    		$shortcode_tag
    	);
    
    	return sprintf(
    		'<a href="https://www.amazon.com/gp/product/%1$s?ie=UTF8&tag=davensjournal-20&linkCode=as2&camp=1789&creative=390957&creativeASIN=%1$s" style="float:left;">%2$s</a>',
    		esc_attr( $atts['isbn'] ),
    		do_shortcode( "[abp:{$atts['isbn']}" )
    	);
    } );

    You’d then use this shortcode in a post etc like [amazon_link isbn=0356510816].

Viewing 1 replies (of 1 total)
  • The topic ‘Not Shortcode’ is closed to new replies.