Pregunta

I've noticed that the admin editor by default embeds any italic texts with <i> which I intend to use for icon styling. I much more prefer to wrap them with an <em>. How would I got about changing this?

¿Fue útil?

Solución

Are you sure editor use <i> for italics? I'm almost sure it uses <em>.

However, if you want to be absolutely sure there are no <i> in your post content, let editor do what it want and then replace <i> with <em> before creating/updating posts, hooking wp_insert_post_data filter, just like:

add_filter('wp_insert_post_data','replace_em', 20, 1);

function replace_em( $post_data ) {
  if ( $post_data['post_content'] != '' ) {
    $post_data['post_content'] = str_ireplace( array('<i>', '</i>'), array('<em>', '</em>'), $post_data['post_content'] );
  }
  return $post_data;
}

Even if you insert <i> manually, they are replaced with <em> on saving.

Licenciado bajo: CC-BY-SA con atribución
scroll top