How do I get wordpress to evaluate a shortcode inside a URL?

I have this shortcode that shows a city name and I need it to be part of the URL of a link.

It’s easy to understand what I’m trying to do just looking at the code:

Read More
<a href='http://chusmix.com/?s=[mmjs-city]'>[mmjs-city]</a>

As you see I just want the shortcode to be part of the URL, I mean add the result of the shortcode to the end of the URL. I have no idea how to do it, probably what I did doesn’t make any sense. Anyway I would be really grateful for any help. Also I’m using wordpress and this code is on a page. Thanks

Related posts

Leave a Reply

2 comments

  1. a simple idea if using jQuery

    you should have

    <a href="http://chusmix.com/?s=" class="underlink">[mmjs-city]</a>
    

    then

    $(".underlink").click(function(){
        document.location = $(this).attr("href") + $(this).text;
    });
    
  2. This would depend on your infrastructure:

    If you use a dynamic backend (recommended)

    To do this, make use of your backend. Use php, jsp, anything to iterate over your cities and generate a link for each of them, with the value filled in (make sure to url-escape the short codes though).

    If you have a static backend, but are creating a dynamic site using JavaScript

    Call some kind of service using Ajax to retrieve your cities. Then generate tags that have the correct url and content. I don’t recommend the suggestion given here to use the onclick event to go to the url, it will break browser functionality, such as ‘open in a new tab’.

    If you’re using static backend and static html

    Nothing to do about it, it’ll be copy-paste action for you 🙂