shortcode – Build Clickable Link Using Multiple Attributes


I am trying to build a function for WordPress (running Elementor, if that matters) that will concatenate 3 items to build a URL, then display that URL in a link that will open in a new window. The start and end of the URL are both static text, and the middle comes from another function via shortcode. I plan to add this to the site in a snippet.

Here is what I have so far. As you will see, I don’t have anything in the heart of the function, which is the “Build URL” section, and I’m not sure if the other sections are done right either. Other than that, it’s pretty much complete 😉

// Function content
function item_link( $atts ) {

    // Only run on pages tied to a single product
    global $post, $product;

    // Get the item data from the shortcode
    $URLslug = do_shortcode( '[contractAddress]' );

    // Set pre- and post- text for URL

    // Build URL
    // This should create clickable link with URL equal to $PREtext + $URLslug + $POSTtext
    // Link text should be 'Click here to view results'
    // Link should open in new window


// Assign function to shortcode 
add_shortcode('See In New Window', 'item_link');

Any help greatly appreciated!

gurs 1 year 2022-06-14T19:23:38-05:00 0 Answers 0 views 0

Leave an answer