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'm looking for a concise PHP filter to add to my functions.php that will search for and strip the following attributes I don't want in my HTML:

  • rel="attachment"
  • rel="attachment wp-att-{x}"
  • rel="category"
  • rel="category tag"
  • rel="bookmark"
  • rel="author"
  • pubdate

I'm happy for all "rel" attributes to be stripped (rather than just what's listed above) if that's easier.

share|improve this question
What is your "theme output"? Are you referring to the_content? – kaiser Sep 10 '12 at 12:24
Sorry, question clarified. – AlecRust Sep 10 '12 at 22:44
I'm sorry too: I still don't understand what you want/need. The "output" or "HTML" of which function exactly? – kaiser Sep 10 '12 at 23:05
Any. I'd like these attributes removed from my whole theme. – AlecRust Sep 11 '12 at 8:54

I wrote a blog post last year about how to remove rel="category tag". Perhaps you can adapt the code to suit your own needs.

// Remove rel attribute from the category list
function wpa_64682_remove_category_list_rel( $output )
    $output = str_replace( ' rel="category tag"', '', $output );
    return $output;
add_filter( 'wp_list_categories', 'wpa_64682_remove_category_list_rel' );
add_filter( 'the_category', 'wpa_64682_remove_category_list_rel' );
share|improve this answer

To make it more clear: (From the comments on the question)

Q: The "output" or "HTML" of which function exactly?

A: Any. I'd like these attributes removed from my whole theme.

WP & Functions:

WordPress has around 2.5k functions with the current version 3.4.2. Now imagine, that we would (or even could) check each function before it is run and then intercept with a str_replace, preg_replace or similar: We would probably slow your theme down by a factor of 10-100.

Alternate approach(es):

NOTE: Not that I'd suggest any of that.

  • You could use ob_start(), etc. and catch the output, parse it and bring it back in.
  • Use js to manually remove it after the DOM has loaded

NOW this is my suggestion: Simply don't do it. The rel="whatever" attributes don't harm anyone or anything. The opposite is the case: Google (and other SEs) have a much easier time finding and indexing your content.

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.