URL with shortcode source returns extra curly bracket

I have a link wrapper URL set to dynamic data > shortcode:

And an example shortcode function:

function link_with_referrer() {
  return 'https://www.testurl.com';
}

add_shortcode( 'link_with_referrer', 'link_with_referrer' );

This used to work, but now it’s returning the URL with an extra curly bracket on the front-end: https://www.testurl.com}

P.S. I’m only using a shortcode since you can’t set a PHP return value as the dynamic data source :slight_smile:

I am not able to replicate this on the latest Cwicly version - it works fine here - I tested with and without square braces on the shortcode.

In what context is your link? Do you get the same behaviour if you create the link in a different context?

Oh really? :thinking: Let me test on a different site.

It’s a CPT single template. Div wrapper with a paragraph inside. The div links to whatever the shortcode returns. Pretty basic setup.

My real snippet (below) is for adding a URL parameter to an ACF field, but I still have the issue with the basic snippet above.

<?php
// Function to get the updated URL with ref=funnelinspo for the specified post ID
function get_updated_url($post_id) {
  // Get the ACF value for the "url" field for the specified post
  $url = get_field('url', $post_id);

  // Check if the URL already contains a query string
  if (strpos($url, '?') !== false) {
    // If it does, append the ref parameter with an ampersand instead of a question mark
    $updated_url = $url . '&ref=funnelinspo';
  } else {
    // If it doesn't, append the ref parameter with a question mark
    $updated_url = $url . '?ref=funnelinspo';
  }

  // Return the updated URL
  return $updated_url;
}

// Add Shortcode
function link_with_referrer() {
  // Get the ID of the current post
  $post_id = get_the_ID();

  // Get the updated URL with ref=funnelinspo for the current post ID
  $updated_url = get_updated_url($post_id);

  // Return the link with the updated URL
  return $updated_url;
}

add_shortcode( 'link_with_referrer', 'link_with_referrer' );

I just tried it on a page and it worked normally.

I wonder if it has something to do with being inside a template.

EDIT: Yup, that’s it. Works fine on static pages, but broken when inside a template.

Hello, you must fill shortcode field without brackets.

[link_with_referrer] => link_with_referrer.

BR.

David.

1 Like

@dmonje, I shared this tip a while ago for the dynamic inserter:

It still works fine on static pages with the brackets though in @sunny’s case.

2 Likes

Thanks @dmonje and @StrangeTech.

Removing the brackets made it work properly again when using inside a template.