Hot answers tagged

14

I recently got this working. You should search and replace metaname with your meta box name. The key to maintaining formatting was using wpautop(); when saving the data. add_action( 'add_meta_boxes', 'add_metaname_box'); add_action( 'save_post', 'metaname_save'); function add_metaname_box() { add_meta_box( 'metaname_id', __( 'metaname ...


6

If this is how it looks: <img class="alignleft size-medium wp-image-8530" alt="..." src="#" width="413" height="275" /> <img class="alignleft size-medium wp-image-8529" alt="..." src="#" width="413" height="275" /> Then you have to put them together like this: <img class="alignleft size-medium wp-image-8530" alt="..." src="#" width="413" ...


5

Here's (a pared-down version of) what I use to custom-configure TinyMCE: // http://tinymce.moxiecode.com/wiki.php/Configuration function cbnet_tinymce_config( $init ) { // Don't remove line breaks $init['remove_linebreaks'] = false; // Pass $init back to WordPress return $init; } add_filter('tiny_mce_before_init', 'cbnet_tinymce_config'); ...


5

Alright so I've already updated this question a ton and it's starting to get overloaded, so I figured I'd write this as an answer even though it isn't a full one. Extrapolating from @bueltge's answer, I actually went back and found his previous post in question. In that post, there was a plugin listed that I've never seen before: "Preserved HTML Editor ...


4

Figured it out, hooking into content_save_pre: function remove_empty_lines( $content ){ // replace empty lines $content = preg_replace("/&nbsp;/", "", $content); return $content; } add_action('content_save_pre', 'remove_empty_lines');


3

The quick fix is to wrap your image tags in div tags. That will prevent WP from wrapping the images in P tags. Then, you could give the divs a class for further control of appearance/arrangement.


3

At first, I think this problem was solved since WP version 3.5; see ticket 19666 in trac. But the tinyMCE have a hook there give us the chance to change the content inside the editor and you must not parse on output on frontend. A small source script. I have no test this with a current WP version, was a older solution for a customer. Add this source via ...


3

Try using get_the_content(); in your page template loop instead of the_content(); EDIT 05/24/2012 - Try this: <div id="main-content"> <?php while( have_posts() ) : the_post() ?> <h1 id="pagetitle"><?php the_title(); ?></h1> <div class="pagecontent"> <?php echo get_the_content(); ?> ...


3

Add to function.php add_filter('tiny_mce_before_init', 'tiny_mce_before_init'); And function tiny_mce_before_init: function tiny_mce_before_init($init) { $init['setup'] = "function(ed) { ed.onBeforeSetContent.add(function(ed, o) { if ( o.content.indexOf('<pre') != -1) { o.content = o.content.replace(/<pre[^>]*>[\\s\\S]+?<\\/...


3

Found perhaps a simpler workaround for this: on the actual template, change this: <?php echo get_the_content());?> to this: <?php echo wpautop(get_the_content());?> This way wpautop() adds the tags stripped out by TinyMCE on a template by template basis.


2

why not you use wordpress new function wp_editor to render the tinymce. That way everything will get handled. And when you show the content to the user apply the filter the_content. Like this: $meta = "content of the metabox"; echo apply_filters('the_content', $meta); The filter the_content will autmatically convert the link brakes to <br> and <...


2

It was a bug in wpautop() which treated <input> as a block element. It is fixed now. See ticket #16456.


2

This seems to have changed a little in subsequent versions of Wordpress. You can now disable this functionality thusly: add_filter('tiny_mce_before_init', function($init) { $init['wpautop'] = false; return $init; }


2

This could probably help, http://codex.wordpress.org/Function_Reference/wpautop This converts the new lines into html <br/> tags


2

I have done extended research and found the answer - I am now using a hook on 'tiny_mce_before_init'. Based on other answers (special thanks to answer #2 @Chip Bennett), I have used the following code in my functions.php to secure the paragraph breaks (in the editor HTML mode they show as &nbsp but become paragraphs on the front-end): function ...


2

There is no filter that would allow you to set allowable tags not to be removed by the_excerpt(). Arguably a shortcoming of the core. Anyhow, the actual excerpt generation does not happen in that template tag but entirely elsewhere: Excerpts are generated by the function wp_trim_excerpt(), inside of which the excerpt filters you are already using (...


2

This seems to do it: function allow_nbsp_in_tinymce( $mceInit ) { $mceInit['entities'] = '160,nbsp,38,amp,60,lt,62,gt'; $mceInit['entity_encoding'] = 'named'; return $mceInit; } add_filter( 'tiny_mce_before_init', 'allow_nbsp_in_tinymce' ); Any improvement suggestions?


2

Converting the comment to an answer, please rename your Shortcode to not contain spaces (new_line): function my_line_break() { return "<br>"; } add_shortcode( 'new_line', 'my_line_break' );


1

Your shortcode name is incorrect . Shortcode API - WordPress Codex So you can write like : function my_line_break() { return "<br>"; } add_shortcode( 'newline', 'my_line_break' ); Then : [newline]


1

You are correct that it is the <br> tags, but there is an alternative: Place each image in their own paragraph, not adjacent lines This is how line breaking works in WordPress content: Paragraphs This is paragraph 1 This is paragraph 2 Short line breaks This is paragraph 1 This is also paragraph 1 but on a new line without a space So don't ...


1

We can not hook wpautop() function. Because then it will trim all the paragraph and break tags from the content. After inserting the image in the editor just click on "Text" tab on the top right corner of the editor and remove the paragraph and break tags that comes in between images. For more options(like alignment and other attributes) click on the image,...


1

This should do the trick: remove_filter('the_content', 'wpautop'); remove_filter('the_content', 'wptexturize');


1

I stuck with the same question and actually tested wpautop(). It worked, e.g. echo wpautop(get_post_meta($post->ID, '_aboutus', true)); Still, I came around one issue. When sanitizing the user input, don’t use a sanitization method that removed the line breaks before using wpautop :)


1

What I like to do is re-create all the default filters that are applied to the_content by adding the following in functions.php. /* * Recreate the default filters on the_content * this will make it much easier to output the meta content with proper/expected formatting */ add_filter( 'meta_content', 'wptexturize' ); add_filter( 'meta_content', '...


1

you could also say that TinyMCE is integrated with WordPress and the HTML editor strips out some characters in favour &nbsp ... this was originally for security and the belief that we didnt need <br> or <p> anymore


1

You can try the CKEditor Wordpress CKEditor


1

First things first, modifying core files is extremely frowned upon you will have to make these changes with every upgrade and they can lead to security and other problems. I'm pretty sure there is a plugin that will allow this. I did a simple search and here are a few to try: http://wordpress.org/extend/plugins/preserved-html-editor-markup/ http://...


1

this is for who use the metaboxes for wordpress: Plugin Name: Meta Box Plugin URI: deluxeblogtips com/meta-box i have modify the /vendor/meta-box/inc/fields/wysiwyg.php in static function : static function html( $html, $meta, $field ) //just after the else i have added : $meta = html_entity_decode($meta); // //and solve the problem ;) -- BUT ...


1

I have also added custom shortcodes to functions.php to avoid things breaking when switching from html to visual editors. Mainly I've used this for iFrame's, but maybe it would be helpful here too.


1

For what it's worth, this has been fixed in 3.4: http://core.trac.wordpress.org/ticket/18311



Only top voted, non community-wiki answers of a minimum length are eligible