WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have seen that Wordpress uses %category% like strings to create url templates. Is there an easy way to allow such mechanism in a plugin? For example in the plugin's settings page user specifies an option

`<a href=%my_url%>Click here</a>`

And in my plugin I replace %my_url% with an actual URL before echoing it.

Is there a function/mechanism in wordpress that I can use to achieve this?

share|improve this question
up vote 2 down vote accepted

You don't need anything WordPress specific here. Use PHP's str_replace to replace tokens entered by users in the settings. In your plugin code, wherever you are echoing the setting value wrap it in str_replace with the value you want to replace %my_url% with.

echo str_replace("%my_url%", $real_url_value, $setting_text);
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.