WordPress TinyMCE : Wrap several elements in DIV

Problem: User wants to know if it is possible to wrap multiple items in a div by using TinyMCE? He wants to avoid using a shortcode.
Here is a setup:

$style_formats = array(
array(
‘title’ => ‘Title with list’,
‘block’ => ‘div’,
‘classes’ => ‘my-class’,
‘wrapper’ => true,
),
);

The result:

Title

  • Some text...
  • Some text...
  • Some text...

But he wants to has something like this:

Title

  • Some text...
  • Some text...
  • Some text...

Solution 1:
I think you have to use a different method to do this. Based on the documentation here:
https://www.tinymce.com/docs/configure/content-formatting/#formats

Take a look here:
https://codex.wordpress.org/TinyMCE_Custom_Buttons

And Here:
http://code.tutsplus.com/tutorials/guide-to-creating-your-own-wordpress-editor-buttons–wp-30182
I haven’t actually done this – I just spent some time researching it a while ago for a client.

Solution 2:
After slightly modified the code User has what he wanted.
He also added a button to remove the div.
Here is the method:
http://community.tinymce.com/forum/viewtopic.php?id=19973

Conclusion:
Above problem is solved by user himself so 2nd solution is correct.but if you have any other idea to solve this problem you can do that. Be creative.

One thought on “WordPress TinyMCE : Wrap several elements in DIV

Leave a Reply

Your email address will not be published. Required fields are marked *