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 want to add a PHP str_replace to the add_filter('the_content') function. I believe my problem is that the shortcodes are loading after the str_replace is called.

I have a shortcode that outputs a form, i want to make it that in all HTML form tags, the attribute autocomplete='off'.

Heres the code i have.

add_filter('the_content', 'disable_autocomplete');
function disable_autocomplete( $content )
{
    return str_replace('<form', '<form autocomplete="off"', $content);
}

Any ideas?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

You can change the priority of actions and filters, it's the third argument of add_filter (and add_action) and it defaults to 10. So change it to a high number and have your filter fire way after the shortcodes and other stuff are inserted.

<?php 
add_filter('the_content', 'disable_autocomplete', 99);
function disable_autocomplete( $content )
{
    return str_replace('<form', '<form autocomplete="off"', $content);
}
share|improve this answer
    
Ahh! So annoying! I put 30 there and it didn't help. Next time ill go higher ;) thanks! –  cnotethegr8 Sep 19 '11 at 17:06

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.