How do I use Shortcodes inside of HTML tags?

Hope this helps someone:

Instead of doing this: <a href="https://example.com/folder/edit.php?action=someaction&id=[foocode parameter="value"]&edittoken=[foocode parameter="othervalue"]">linktext</a>

You can do this: [foocode parameter1=value parameter2=othervalue] and then do this:

add_shortcode( 'foocode', 'prefix_foocode' );

function prefix_foocode( $atts ) {

    // Normalize $atts, set defaults and do whatever you want with $atts.

    $html="<a href="https://example.com/folder/edit.php?action=someaction&id=" . $atts['parameter1'] .'&edittoken=' . $atts['parameter2'] . '">linktext</a>';
return $html;
}

Leave a Comment