WP Plugin: rm_wpautop

De vez en cuando, es necesario decirle a WordPress que uno prefiere no utilizar su función de ‘wpautop’ (un generador de elementos de párrafo automático). Y para esas situaciones está este plug-in.

<?php
/*
Plugin Name: rm_wpautop
Plugin URI: http://rolandog.com/archives/2008/11/12/wp-plugin-rm-wpautop/
Description: This plugin allows you to remove the wpautop filter by placing a 'wpautop' custom field with a key value of 'false' in your pages or posts, therefore allowing WordPress not to automatically add paragraph or break elements.
Author: Rolando Garza
Author URI: http://rolandog.com/
Version: 0.3
*/
function rm_wpautop($content) {
    global $post;
    // Get the keys and values of the custom fields:
    $rmwpautop = get_post_meta($post->ID, 'wpautop', true);
    // Remove the filter
    remove_filter('the_content', 'wpautop');
    if ('false' === $rmwpautop) {
    } else {
    // Adds the filter again, if not set to false.
        add_filter('the_content', 'wpautop');
    }
    return $content;
}
// Hook into the Plugin API
add_filter('the_content', 'rm_wpautop', 9);
?>

Aquí se los dejo, espero que les sirva. Yo actualmente lo estoy utilizando en este post, y en la página de Math.js, para que valide como XHTML.

Instrucciones manuales:

  1. Copiar y pegar el código, guardarlo como rm_wpautop.php
  2. Subirlo a la carpeta de /wp-content/plugins/
  3. Activarlo
  4. Colocar un Custom Field con Key de wpautop y valor false en la página en la que desees que no se generen breaks automáticos.

rm_wpautop.zip, para simplemente subir e instalar a través de la interfaz.

Este plug-in lo diseñé específicamente para páginas (o para el single page de un post), pero pronto intentaré adaptarlo para que también lo haga para posts. La versión 0.3 del plug-in permite. Que cualquier post — independientemente de si aparece en una página de archivos o categorías, o en la página principal, pueda deshabilitar el filtro ‘wpautop’ de WordPress.

Printed from: http://rolandog.com/archives/2008/11/12/wp-plugin-rm_wpautop/ .
© Rolando Garza 2010.

19 Comments   »

  • Adjani says:

    Mira.. Eso si ayuda bastante por el espacio..
    Saludos.

  • ChicaRegia says:

    Que bien!
    Tengo que aprovechar el puente que viene para arreglar todos mis errores también!

  • Glark says:

    Hi! I came here from your posts on the WP forums. I was wondering if there was a way to make the plugin also work with pages?

  • rolandog says:

    Hi Glark. The plug-in is actually designed to work with posts and pages. If you have any trouble don't hesitate writing back.

    I'm going to add read-me and other stuff to the plug-in so that it can be added to the word press plug-in directory. =)

  • vitto says:

    hi
    i just loaded your plugin on mu wp but i don't know how to use it.
    what do you mean by
    Custom Field con Key de wpautop y valor false.

    Where should i write it and what?
    Many thanks
    Vitto

  • vitto says:

    sorry
    i just found my way out!
    Thanx again
    Vitto

  • rolandog says:

    Nice to see you found a workout. I actually didn't think if it'd work with WordPress MU. Was it straight-forward?

  • vanessa says:

    hi, i have the same question as the last commenter but i can't seem to figure it out for myself. how do i manually set the custom field?

  • Michael says:

    I am trying to get this to work on a page in WP 2.8 but it is not working. Any advice?

    Thanks!

  • rolandog says:

    Michael :

    I am trying to get this to work on a page in WP 2.8 but it is not working. Any advice?

    Thanks!

    It's working fine with my installation. Have you added the Custom field named 'wpautop' with 'false'?

  • Cole says:

    I am so frustrated with Autop and your plugin seems great, with the exception that I can't seem to get it to work. (At least I think). WP actually doesn't insert p tags but it is inserting /p tags which means my code is still invalid. Is that how this works? Or is it just not working? Any ideas either way? Could you show me a post or page where it does work, maybe? I am using the custom field and my WP is 2.8.4 so it should work as far as I know.

  • rolandog says:

    Hi Cole,

    I think it's my fault... I may not have updated the zip file the last time (it had an error in the instructions, since I changed the method so that it was logical to use 'wpautop' and 'false')... but the snipplr code that is shown should work properly.

    Actually the whole rm_autop post is using rm_wpautop (i inserted 'p' elements with 'omg' 'wtf' 'bbq' and 'lol' ids) and this page also uses it: http://rolandog.com/math-js/

    If you want, you can update your plug-in through wordpress (copy paste the plain text version in snipplr: http://snipplr.com/view.php?codeview&id=9699 .

  • Dorian says:

    Hello,
    Nice one, I really like your plugin because a lot of my pages are now W3C Valid.
    However, I cant seem to make it work with pages that are already written by rewriting them. I have to delete them completely and create new ones (what a hassle!).

    Is this normal ?

    sorry for writing in English here, I'm not that good at Spanish so I'm not risking it !

  • Dorian says:

    Actually the plugin just doesn't work for pages, only for posts - just like someone else who posted here.

    Is there a workaround for that ?

  • ABsolute says:

    Hello,

    I like your plugin, but it wont work for pages.

    What does "Place a Custom Field to Key wpautop and false on the page where you want to generate breaks that are not automatic." mean ?

    Since the code posted here does not work, where do I place those fields and how ?

    Thanks in advance!

  • rolandog says:

    Dorian :

    Hello,
    Nice one, I really like your plugin because a lot of my pages are now W3C Valid.
    However, I cant seem to make it work with pages that are already written by rewriting them. I have to delete them completely and create new ones (what a hassle!).

    Is this normal ?

    sorry for writing in English here, I’m not that good at Spanish so I’m not risking it !

    I've never heard of this issue before.

    But I think I may know what the problem is. You may be using a caching plug-in and that delays any updates from showing up.

    Is this the case? If so, purge or re-build your cache.

  • rolandog says:

    @ABsolute
    You need to specify a custom field called 'wpautop' with a value of 'false' so that the plug-in knows when and when not to remove the wpautop auto-formatting.

    If you've already used a wpautop custom field, you may then find it in a drop-box (like so). Otherwise, you'll have to click on 'enter new'

  • Dorian says:

    OK, I'll give that a try and let you know.

    Thanks for your reply.

  • CurtainDog says:

    Hi rolandog,

    Great plugin... should be part of core WordPress.

    Thanks.

Trackbacks/Pingbacks

  1. Bitacoras.com
  2. Pistache Pelado » Optimizar Wordpress Para los Motores de Búsqueda

RSS feed for comments on this post , TrackBack URI

Leave a Reply

  • A long, long time ago…