How to modify wpautop to add tabs before <p> (16 posts)

  1. Jonathan Landrum
    Posted 7 years ago #

    I'm interesting in finding a way to make the code a WordPress site produces indented. I've considered writing the posts in a text editor and pasting the code in the textbox on the write post page.

    I've also tried to think of a plugin that would somehow modify wpautop to place four or five \t tabs before each paragraph opening tag. Any ideas how to do this?


    		<title>An Indented Source</title>
    		<h1>An Indented Source</h1>
    			<div class="post">
    				<p>An indented paragraph within the_content().</p>
  2. stvwlf
    Posted 7 years ago #

    If you are talking about indenting the first line of a paragraph, there is a way to easily do that using CSS.

    text-indent: 20px

    add it into your stylesheet. On most themes this will do it:
    #content p { text-indent: 20px }

    If you are talking about indenting every line of every paragraph, you can just increase the margin or padding on the container in which the post content appears. Then everything will appear indented.

  3. Jonathan Landrum
    Posted 7 years ago #

    No, this has nothing to do with CSS. In fact, it has nothing to do with display at all. In the code above, I showed a sample HTML source. What I am trying to accomplish is "pretty-printed" code.

    There are functions to do this for PHP code, but how about the HTML it produces?

  4. Jonathan Landrum
    Posted 7 years ago #

    There should be a way to edit wpautop to do this automatically.

    I once tried editing it to replace \n\n with </p>\n\t\t\t\t<p>. But it didn't work. But shouldn't that do it? Or am I doing something wrong?

  5. whooami
    Posted 7 years ago #

    .. and I thought I was anal :P

    Im sorry, I just couldnt resist.

    I went on a coding tangent until my my wp_head stuff was EXACTLY how I wanted it, so I really do understand the inclination.

  6. Jonathan Landrum
    Posted 7 years ago #

    :~] I've always known you were anal, whoo. You were actually the first one to make *me* that way!

    So, can you think of any way I can achieve this?

  7. whooami
    Posted 7 years ago #

    OMG!! Youre blaming me??!!!

    hahahahah!! :) I so love that :)

    I will have to think about that. I know on this most recent site I set up, I thought about toying with that, and scrapped it all together.

    Have you discovered that messing with the actual core code was not doable, because of upgrades, or just because it was unrealistic? Assuming you decided that, of course.

  8. Jonathan Landrum
    Posted 7 years ago #

    Both. Since I've gotten my source via Subversion, and since Cron updates it every night, it would only be a matter of time before my hack disappeared.

  9. Jonathan Landrum
    Posted 7 years ago #

    I could disable wpautop in a plugin, and after that function add the above code.

    I saw a fellow once whose source was simply gorgeous. Each paragraph was indented, no doubt, but each line broke after a certain number of characters, and the wrapped lines were indented, plus three spaces:

    	<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
    	   Etiam adipiscing, tellus sed consequat euismod, felis turpis
    	   tristique magna, vel placerat sem arcu eget lorem. Aliquam
    	   aliquet, sapien a tincidunt vulputate, mauris ligula sagittis
    	   tortor, sed egestas ante est vitae velit. Etiam pharetra.
    	   Pellentesque mattis, tortor sed congue consequat, neque enim
    	   ornare tellus, quis dapibus nisl nisi nec risus. Ut eget
    	   erat. Proin lacinia nunc at enim. Vivamus adipiscing
    	   fringilla metus. Mauris hendrerit. In rhoncus metus sed
    	   velit. Praesent diam diam, varius eu, egestas pharetra,
    	   euismod id, sem.</p>
    	<p>Curabitur dapibus. Mauris tincidunt mollis lacus. Ut ac
    	   justo. Phasellus faucibus diam non dui. Vivamus ut est. Nam
    	   et risus sit amet metus aliquam pharetra. Vivamus
    	   sollicitudin mauris at nisl. Sed tincidunt sollicitudin est.
    	   Proin pharetra. Donec euismod gravida est. Maecenas a sem.
    	   Aliquam erat volutpat. Praesent nibh. Aenean nisl tortor,
    	   porttitor sed, malesuada sit amet, dictum eget, lectus. Donec
    	   laoreet ante quis metus.</p>

    That is what I really would like to get to.

    Edit: Bah! Even here, with code marked up as such, it's an un-attainable goal!

    Edit 2: It doesn't like spaces after the code mark.

  10. whooami
    Posted 7 years ago #


    I wish my roommate were so inclined -- maybe he would sweep once in a great while

  11. Jonathan Landrum
    Posted 7 years ago #

    wp-includes/classes.php has some interesting code beginning at line 498:

    $indent = str_repeat("\t", $depth);

    $depth being a function previously defined.

  12. Jonathan Landrum
    Posted 7 years ago #

    How about:

    remove_filter ('the_content', 'wpautop');
    remove_filter ('the_excerpt', 'wpautop');
    $prettyPrint = str_replace("\n\n", "</p>\n\t\t\t\t<p>", $prettyPrint);
    add_filter ('the_content', 'prettyPrint');
    add_filter ('the_excerpt', 'prettyPrint');
  13. Jonathan Landrum
    Posted 7 years ago #

    This doesn't work, but it's where I'm at:

    $t = str_repeat('\t', 4);
    $lineWidth = 75;
    $n = $n . PHP_EOL;
    $space = $space . '   ';
    function prettyPrint($code) {
    	// Don't Reformat Between Pre Tags
    	if (eregi('<%pre%[^>]*>(.*?)</%pre%>', $code)) {
    	// Blockquote Formatting
    	if (eregi($n . $n . '<%blockquote%(.*?)>', $code)) {
    		$code = preg_replace($n . $n . '<%blockquote%(.*?)>', '</p>' . $n . $t . '<blockquote $1>', $code);
    	// Paragraph Formatting
    	if (eregi($n . $n, $code)) {
    		$code = str_replace($n . $n, '</p>' . $n . $t . '<p>', $code);
    	// Line Break Formatting
    	if (eregi($n, $code)) {
    		$code = str_replace($n, '<br />' . $n . $t . $space, $code);
    	return $code;
    remove_filter ('comment_text', 'wpautop');
    remove_filter ('the_content', 'wpautop');
    remove_filter ('the_excerpt', 'wpautop');
    add_filter ('comment_text', 'prettyPrint', 10);
    add_filter ('the_content', 'prettyPrint', 10);
    add_filter ('the_excerpt', 'prettyPrint', 10);
  14. Jonathan Landrum
    Posted 7 years ago #

    Perhaps I should declare the variables global.

  15. Creap
    Posted 7 years ago #

    Did you fix it at last? Code is poetry...

  16. Jonathan Landrum
    Posted 6 years ago #

    No, it never worked. I'm still searching for a way.

Topic Closed

This topic has been closed to new replies.

About this Topic