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.

EDIT 2

The following edit has some mis-information, see the selected answer and comments.

EDIT

I am a fool. The editor was in fact adding <p> tags as expected. I was using a combination of get_the_content() and the_content(). Apparently the former will strip out these tags, just leaving a block of text (which still leaves me in a predicament but im sure I'll figure something out)

follow up question: should I delete this question? or is this kind of thing helpful to have in the search....?


When I paste text from different sources into the wordpress (tinyMCE) content visual editor I am getting different results. Ironically, it works how I want it to when pasting from MSWord, but not when going from notepad (or another website, or notepad++).

Ideally I would want any pasted text to get wrapped in <p> tags (based on line breaks) and otherwise have minimal markup added.

The big issue here is the <p> : linebreak issue. I want the client to be able to paste a few paragraphs of text in and be able to set the margins and padding so as to make it look nice.

This must be a pretty normal expectation, and I am suprised that I am having difficulties with this, as I have built several WP sites before without noticing this issue.

share|improve this question
    
heh... -1. I deserved that ;-). What should I do in circumstances like this (when I realize I asked a stupid question). I kind of want to delete, but am reluctant to do so because of the excelent anwswer below, and the possibility that this might be useful for another someone else in the future. –  Zach L Nov 2 '11 at 15:36
    
In the future, either write an answer explaining how you figured out what was wrong, or accept whatever answer someone else provided explaining what was wrong. You aren't the first to ask a question like this, and you won't be the last. –  EAMann Nov 2 '11 at 15:51

1 Answer 1

up vote 2 down vote accepted

Facilitating users to write content in an external editor, and then copy/paste it into the WordPress editor, is a fundamentally bad approach, and is fraught with issues. The WordPress editor is intended to be used to write content. You should train your users to use the post editor to write content, as opposed to using it as a receptacle for pasting content from another editor.

When I paste text from different sources into the wordpress (tinyMCE) content visual editor I am getting different results.

That's because WordPress is not intended for copy-pasting content into the editor, but rather for using the editor to write content.

Ironically, it works how I want it to when pasting from MSWord, but not when going from notepad (or another website, or notepad++).

That's because WordPress includes a hackish Paste-From-Word button, to placate the people who persist in this unintended use of the WordPress post editor.

The big issue here is the

: linebreak issue. I want the client to be able to paste a few paragraphs of text in and be able to set the margins and padding so as to make it look nice.

The paragraph tags are added automatically by an output filter. If you need to adjust the style of the paragraphs, you should do so via CSS, not in the post editor.

This must be a pretty normal expectation, and I am suprised that I am having difficulties with this, as I have built several WP sites before without noticing this issue.

The main thing is to ensure that the copy-pasted content actually has newlines, so that WordPress can add the paragraph tags where appropriate.

EDIT

I was using a combination of get_the_content() and the_content(). Apparently the former will strip out these tags, just leaving a block of text (which still leaves me in a predicament but im sure i'll figure something out)

Actually, it's not that get_the_content() strips out <p> tags, but rather that the <p> tags are applied via filters applied to the_content(), specifically, wpautop().

If you need to apply content filters to content returned by get_the_content(), use the following:

<?php
$some_content = apply_filters( 'the_content', get_the_content() );
?>

That will manually apply all content filters to get_the_content().

share|improve this answer
    
WOW chip. Thank you for this thorough answer. I feel pretty guilty now that I was operating under false presumptions, but this answer is still relevant for me. I do have one issue however. I think it is unrealistic (at least when using WP as a CMS) to expect users to re-type info rather than cut-pasting. For example, I have a custom post type with bios for board members (around a page in length each). It would be common for the site admin to request a bio from the board member (by email). It would be crazy to ask them to retype this information every time. –  Zach L Nov 2 '11 at 15:32
    
You certainly shouldn't re-type such text by hand. You just might need to be aware that copy-pasting such text may require re-applying line-breaks in the pasted content. p.s. WordPress is always used as a "CMS"; that's what it is, after all. ;) –  Chip Bennett Nov 2 '11 at 15:45
    
Also: see updated answer, with respect to filters applied to the_content() and get_the_content(). –  Chip Bennett Nov 2 '11 at 15:49
    
Thanks Chip, that's right on the money. –  Zach L Nov 2 '11 at 20:29

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.