I would like the default <p> elements that are added to the (TinyMCE) editor when users post content, to have a dir attribute as well.

Reasoning: When the editor is displayed to users, it is wrapped in an html element with a dir attribute (determined by locale). Thus, the text direction to the user (while he is writing the content) reflects his locale.

However, the p elements that are part of the user's content (which I will be storing in the database) do not have the dir attribute attached.

I would like to attach it so that when the content is later retrieved from the database, it is shown the same way that it looked to the user/author when he wrote it.

How can I add the dir attribute to the p tags by default?

Another Approach: I have directionality buttons as part of my editor, if I can select these buttons by default, this will take care of the problem as well.

Thank you.

  • 2
    The <p> tags are added by wpautop() during output. It would probably make more sense to save meta data that specifies the author's original direction. Then prior to outputting the content, check the meta value and add a class to the entire wrapping element for the content. – Dave Romsey Sep 27 '16 at 7:15
  • That sounds like it might work. I'm not too keen on how to insert and retrieve post metadata (I'm just tweaking a q&a plugin) but I guess that's for another question if necessary. Thanks. – theyuv Sep 27 '16 at 7:36
  • @theyuv It's very, very easy - you can just use the built-in "Custom Fields" metabox to allow the user to add/edit/delete custom fields, and then pull them in with get_post_meta( $post_id, 'name_of_field', true ) – TheDeadMedic Sep 27 '16 at 9:32
  • @TheDeadMedic Yup, I'm working on it now. Just difficult in the sense that I have to find where my plugin writes the posts to the DB and stuff (I'm a novice at php and WP). But I think I should be able to do this. And yes, the WP functions make it easy. Thanks. – theyuv Sep 27 '16 at 9:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.