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.

21 Comments

  • Información Bitacoras.com…

    Si lo deseas, puedes hacer click para valorar este post en Bitacoras.com. Gracias….

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

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

  • 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?

  • 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 wrote:

    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 wrote:

    sorry
    i just found my way out!
    Thanx again
    Vitto

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

  • [...] Segundo. XHTML válido en todas partes. E inclusive, ¡hay que subir la barra! Si utilizan XHMTL 1.0  Transitional, tratar de validar siempre como XHTML 1.0 Strict. Para eso hay que meterse a fondo a la plantilla y no tenerle miedo a los cambios. Si van a hacer muchas modificaciones, copien todo el contenido del documento — por si acaso — a un documento de texto (no de Word); así se pierde el miedo a modificar cosas y haciendo prueba y error.  Hay que perderle el miedo a los códigos de <?php instrucciones(); ?>. Primero hay que intentar editar afuera de el código PHP y, si no hay de otro remedio, hay que aprender qué es lo que está haciendo el lenguaje ahí. Y, adicionalmente, habrá ocasiones en las que será necesario editar manualmente el HTML de el artículo que estemos escribiendo. Para eso, les recomiendo un plug-in que escribí llamado rm_wpautop. [...]

  • vanessa wrote:

    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?

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

    Thanks!

  • 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’?

  • 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.

  • 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 wrote:

    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 wrote:

    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 wrote:

    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!

  • 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.

  • @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 wrote:

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

    Thanks for your reply.

  • CurtainDog wrote:

    Hi rolandog,

    Great plugin… should be part of core WordPress.

    Thanks.

Post a Comment

Your email is never shared. Required fields are marked *