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 find myself more and more needing to use tables or divs inside my wordpress posts content. The problem I find with this is that one wrong backspace or newline, copy / paste has the possibility to throw off the whole code. Is there a best practices when it comes to adding html inside the content? Is there a way to make it so that the user cannot delete certain things inside posts content?

For Example: On one of my websites I have an accordion. Each accordion content is seperated by div class="accordContent" but when the user adds a new line inside the current accordContent div, it ends the current div and creates a new one with the same class that throws off the code.

share|improve this question
    
I think it's best not to add html markup in post content, instead it should be added in template files. –  Vinod Dalvi Sep 9 '13 at 13:56
    
I mean, by default the wordpress tinyMCE doesn't come with any kind of table setups. And usually, the user doesn't ever really need to add a new row or TD, but edit the content inside the table. –  Howdy_McGee Sep 9 '13 at 14:00
    
1) create shortcodes that handle all tour needs 2) add buttons to tinyMCE that help to insert shortcodes. –  G. M. Sep 9 '13 at 14:04
    
For creating tables in content you can use these plugins wordpress.org/plugins/wp-tinymce-tables wordpress.org/plugins/ultimate-tinymce –  Vinod Dalvi Sep 9 '13 at 14:05
    
@VinodDalvi right I know there is plugins for this sort of thing but for the most part I try to stay away from plugins. G.M. you're probably right that shortcodes are the best solution. –  Howdy_McGee Sep 9 '13 at 14:09
show 1 more comment

1 Answer

up vote 1 down vote accepted

Is there a way to make it so that the user cannot delete certain things inside posts content?

You need...

  1. A shortcode that will generate the content. This will let your users provide input but the markup can be rigidly controlled.
  2. Or a custom meta field. The markup around this can also be rigidly controlled, but to a lesser extent, or in a different way.
  3. Or you need to write the markup into the templates.

I can't tell you exactly which you need. I'm not sure. I think the shortcode, or a group of shortcodes, might do what you need.

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.