Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.