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.

Going crazy with this. Can't figure out if this is normal behavior.

I have added a filter to rewrite image inserts to use <figure> and <figcaption>. Works well.

However, when I insert an image in the Visual view and press return, I want it to start a new paragraph.

Instead it creates another <figure> element and puts my next line of text in that.

Example of the code produced if switch to Text view:

<figure class="alignnone">

<a href="path/to/image.jpg"><img class="alignnone size- wp-image-209" src="path/to/image.jpg" width="199" height="43" /></a>

<figcaption>Image Caption</figcaption>

</figure>

<figure class="alignnone"`>This should be a new paragraph but is inside a figure tag.</figure>

Is there any way I can stop tinyMCE from replicating the previous block element? I know if you set some text as, say, an <h2> and press return the next line defaults back to <p>. That's the behavior I want.

share|improve this question

1 Answer 1

I'm currently having the same problem. Here's my work-around.

add_filter( 'tiny_mce_before_init', 'workaround' );
public function workaround( $in ) {
    $in['force_br_newlines'] = true;
    $in['force_p_newlines'] = false;
    $in['forced_root_block'] = '';
    return $in;
}

tiny_mce_before_init gives you access to the TinyMCE settings that WordPress' editor uses. See also: TinyMCEConfiguration

The downside to this is instead of "return" resulting in a p it instead gives you a br. I've tried reversing the force_br_newlines and force_p_newlines but it results in the original problem. Hope this is of some help.

share|improve this answer

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.