Home › Forum › Problemi Vari con WP › wordpress toglie i paragrafi (wp 3.4.1)
-
AutorePost
-
-
22 Luglio 2012 alle 23:33 #22202peppe01Partecipante
Problema con l’editor di wordpress. Mi occorrre scrivere il testo degli articoli con i paragrafi, invece l’editor li toglie.
L’articolo dovrebbe essere, in breve, cosà¬
<h2>titolo</h2>
<p>paragrafo</p>
<h3>titoletto</h3>
immagine
immaginedopo il salvataggio i paragrafi spariscono e l’html diventa cosà¬
<h2>titolo</2>
paragrafo
<h3>titoletto</h3>
immagine
immagineDopo varie ricerche sono arrivato a modificare la linea 32 del file wp-includes/class-wp-editor.php
'wpautop' => true, // use wpautop?
in
'wpautop' => false, // use wpautop?
ma il risultato è stato bizzarro perché wp ha aggiunto paragrafi un po’ a caso
<h2>titolo</h2>
<p>paragrafo</p>
<h3>titoletto</h3>
<p>immagine
immagine</p>mettendo le due immagini dentro lo stesso paragrafo. Io invece vorrei semplicemente che l’editor lasciasse i paragrafi come li scrivo.
Nello stesso file ci sono due righe sospette
'apply_source_formatting' => (bool) !$set,
'remove_linebreaks' => (bool) $set,non sono un programmatore quindi sono andato un po’ alla ceca provando a rimuoverle, ma non ho avuto risultati.
Qualcuno può aiutarmi?
grazie
ps
so che ci sono diversi post sull’argomento, mi sembra in due giorni di averli letti tutti, quindi a questo punto non ho più risorse.
La versione di wordpress è la 3.4.1 e il tema è il twentyeleven. La funzione di correzione del codice xhtml annidato non è spuntata.
-
23 Luglio 2012 alle 21:41 #96764TittiModeratore
Non si modificano i core file di WP, tanto meno “alla ceca”.
E non esistono “righe sospette” nei file originali di WP.
-
24 Luglio 2012 alle 1:04 #96767peppe01Partecipante
Ho usato i termini alla cieca e righe sospette con auto ironia per enfatizzare il mio dilettantismo, in realtà in 4 giorni di ricerche ho incontrato ‘wpautop’ => true, // use wpautop? qualche centinaia di volte, sopratutto sui forum internazionali…
Comunque ho trovato la soluzione al mio problema, forse incompleta e raffazzonata ma funziona, quindi la posto perché mi sembra di aver riscontrato un certo interesse per il problema, poi qualcuno + bravo e competente potrà fornire soluzioni migliori.
1) come sopra ho modificato il file wp-includes/class-wp-editor.php alla riga 36
'wpautop' => true, // use wpautop?
in
'wpautop' => false, // use wpautop?
Disabilitando il filtro messo dagli sviluppatori dell’editor di sistema TinyMCE per evitare che wordpress metta paragrafi ovunque.
A questo punto ho avuto il problema che wordpress ha inizato a mettermi paragrafi alle immagini, e se la immagini sono due il risultato è
<p>immagine immagine</p>
2) ho apportato la modifica al file function.php nel mio tema aggiungendo alla fine del file il seguente codice
<?php
function filter_ptags_on_images($content){
return preg_replace('/<p>s*()?s*()s*(</a>)?s*</p>/iU', '123', $content);
}
add_filter('the_content', 'filter_ptags_on_images');
?>
Il mio problema mi sembra risolto, anche se devo fare ancora un po’ di test. Mi sono accorto per esempio che con il tag a se si trova fuori dal paragrafo ci mette p, poco male, e magari all’occasione si risolve pure quello.
Aggiungo che con gli aggiornamenti il file wp-includes/class-wp-editor.php potrebbe essere sovrascritto, nel qual caso dovrei ri-effettuare la modifica. In ciò potrebbe venirci incontro qualcuno più esperto per indicare come risolvere il problema in modo meno invasivo.
Per finire cito la fonte della mia ispirazione nel modificare il file function.php css-tricks.com/snippets/wordpress/remove-paragraph-tags-from-around-images
Mentre per la modifica del file wp-includes/class-wp-editor.php (scusate se è core) http://codex.wordpress.org/TinyMCE
Grazie a tutti per il gentile aiuto
-
24 Luglio 2012 alle 20:34 #96781TittiModeratore
I link che hai messo non portano a nulla, ma conta poco che il suggerimento sia internazionale o nazionale. Ripeto, i file di WP del core non vanno modificati, non solo perché a ogni aggiornamento perdi le modifiche di sicuro (non forse), ma anche perché non sapendo quello che stai facendo puoi creare vulnerabilità che non potrai risolvere se non rimettendo il file originale. Inoltre in caso di problemi di qualsiasi tipo non saprai se è a causa delle modifiche che hai fatto.
Poi, anche se tu fossi disposto a rifare il lavoro ogni volta dopo l’aggiornamento, non essendo un programmatore non sapresti che fare se il file da modificare è cambiato, o non c’è più.
WP dev’essere usato cosଠcom’è nel pacchetto dal 99,9% (percentuale a caso per non dire 100%) degli utilizzatori: è tanto semplice come concetto che è quasi banale dirlo. Chi modifica i file del core su un sito in produzione proprio o altrui e lo fa con cognizione di causa o con buone ragioni non può che essere una persona che non ha certo bisogno di leggere come fare su qualche articolo nel web, sto parlando di uno sviluppatore di WP, ad esempio.
Per tutti gli altri, ci sono estensioni per avere modifiche da poter tenere sotto controllo dal proprio backend, scrivi o fai scrivere un tema o un plugin se vuoi ottenere qualcosa che non trovi già fatto.
Su questo forum nessuno ti proporrà una soluzione al tuo problema senza che tu ti metta nella condizione di avere WP standard come partenza minima e necessaria, e facendo le prove con tema di default e plugin disattivati: solo in questo situazione se il problema si presenta è un problema di WP, altrimenti no.
-
24 Luglio 2012 alle 21:09 #96787San PietroburgoPartecipante
Se cercavi meglio wpautop, nel repository di WordPress (e qui nel forum perché ricordo di averne già parlato), esiste da molti anni un plugin che fa quel che descrivi senza modificare file del core e tema; queste ultime sono modifiche che oltretutto dovrai rifare ad ogni nuovo aggiornamento (cito e quoto Titti), il plugin esiste proprio per semplificare il mezzo..
-
24 Luglio 2012 alle 21:19 #96788peppe01Partecipante
Ne sono certo, hai ragione tu, tuttora sto cercando un modo di risolvere il problema in maniera più ortodossa, tuttavia non posso non lamentare il fatto che questo sia un problema piuttosto sentito a giudicare dalla notevole quantità di discussioni alimenta sui forum di tutto il mondo, e che tutto sommato la tua risposta mi sembra alzare un muro tra chi può e chi non può, atteggiamento piuttosto diffuso sopratutto nei forum in lingua italiana. Altrove nel pianeta invece spesso c’è più apertura verso tutti gli altri, i non esperti, schiera variegata di persone con istanze diverse, tra loro trovi anche tuoi futuri colleghi che si stanno accostando alla materia e vogliono un po’ ficcare il naso, smanettare, magari rompere e poi aggiustare, anche cosଠè cresciuto l’open source.
Tanto per la cronaca i link di cui sopra sono
http://codex.wordpress.org/TinyMCE e
http://css-tricks.com/snippets/wordpress/remove-paragraph-tags-from-around-images/
Grazie comunque per l’interessamento
-
24 Luglio 2012 alle 21:25 #96789San PietroburgoPartecipante
Ad interferire con l’editor ci sono molti script e js, tutto dipende da cosa abbiamo aggiunto a WordPress, inteso per tema e plugin.
WordPress non sbaglia se installato come rilasciato, cioè con uno dei due temi di default (uno XHTML1 e l’altro HTML5).
Quando invece andiamo a installare un altro tema e decine di plugin, senza sapere nemmeno se saranno compatibili con il codice HTML utilizzato nelle pagine del sito, capitano questi pastrocchi.
-
24 Luglio 2012 alle 21:43 #96791San PietroburgoPartecipante
@edit
Lo stesso TinyMCE non è un editor HTML5, quindi WordPress lavora in due modi differenti a seconda di quale tema, tra i due di default, andremo ad utilizzare.
Nel caso di TwentyEleven, ad esempio, aggiungerà filtri ed interpreti per far si che le pagine abbiano codice validato HTML5 (o almeno ci prova visto che lo stesso codice non è ancora definitivo).
-
24 Luglio 2012 alle 22:05 #96793TittiModeratore
@peppe. Io non innalzo nessun muro, non hai capito, o perlomeno non del tipo che intendi tu (perché fra me e uno sviluppatore di WP il muro c’è, eccome). Il mio discorso era che nessun utente dovrebbe modificare il core di WP, per i motivi di cui sopra. Poi ognuno può fare quello che vuole, chi ha detto che non puoi? Fai quello che vuoi, se sai o vuoi gestirne le possibili conseguenze.
Se sei venuto qui significa che avevi bisogno di un consiglio, e quello non è un mio consiglio, è una buona prassi che tutti dovrebbero adottare. Perché? Per non avere problemi, come detto, non ci sono altre motivazioni di tipo “morale”. Non s’intacca il concetto dell’open-source.
Il consiglio di non modificare i file del core immagino ci sia non solo in lingua inglese, ma tedesca, francese, spagnola, serbo-croata… cosଠcome il contrario naturalmente, ed è chiaro che il materiale vario su ogni tipo di questione riguardante tutto lo scibile umano, compreso WordPress, bella o brutta, buona o cattiva, si trova in lingua inglese.
Io comunque non ho mai avuto quel problema, anche perché uso l’editor HTML.
-
24 Luglio 2012 alle 22:14 #96796peppe01Partecipante
Non credo sia questo il caso, come ho scritto all’inizio La versione di wordpress è la 3.4.1 e il tema è il twentyeleven. i plugin installati e attivi al momento sono 3, maintanance per mettere il sito off-line, xili-language per il multilingue e wp-slidesjs per creare una slide con gli articoli di una categoria.
Le modifiche sul tema le ho apportate su un tema child di twenty-eleven creato dagli sviluppatori di xily.
Poi ho provato ad installare un’altro editor che però non ha risolto il problema e quindi l’ho disattivato e disinstallato, e altri plugin allo stesso scopo che ho comunque rimosso.
In ogni caso quanto prima disattivo tema-child e plugin per vedere se effettivamente qualche cosa interferisce con l’editor, ma come ho sempre scritto sopra credo di aver capito che wordpress applichi dei filtri ai contenuti degli articoli inseriti da editor, che in linea di massima sono utili alla gran parte degli utenti, ma dannosi nel caso specifico di alcuni, o no?
-
24 Luglio 2012 alle 23:01 #96798
-
24 Luglio 2012 alle 23:53 #96799peppe01Partecipante
Grazie titti, li provo senz’altro, anche se il primo, tiny-mce advanced lo avevo visto ma mi aveva un po’ preoccupato perché ho letto che installa 16 plugin e non so se questo potrebbe crearmi qualche problema se non altro per disattivarli tutti nel caso non faccia al caso mio. Nel frattempo seguendo i vostri consigli e cercando wpautop ho trovato anche il plugin Advanced TinyMCE Config, che permette di intervenire sulla configurazione dell’editor, devo dire che è piuttosto “advanced” ma sembra che riesca a farlo funzionare.
Ho anche trovato TRUEedit, un plugin che promette di disabilitare i filtri per poter editare l’html senza problemi, ma mi sembra non funzioni, forse la ragione è quella che diceva San Pietroburgo circa html5 wp e l’editor.
Certamente se trovassi un’editor che non mi crea il problema sarebbe molto più semplice. Vi faccio sapere come va intanto grazie a tutti
-
25 Luglio 2012 alle 18:13 #96815San PietroburgoPartecipante
Non posso metterci la mano sul fuoco ma penso i problemi che riscontri siano dovuti al plugin xili-language. Problemi simili li aveva anche qTranslate ma li abbiamo risolti.
Per cercare di capire dovrai fare alcuni test; test che vanno sperimentati in locale e non nel sito web in produzione.
Dette prove serviranno a verificare dove avviene il pastrocchio..
In pratica si tratta di utilizzare WordPress di default (solo lui ed il tema) e poi ancora, WordPress con la tua configurazione, tema child ed il plugin xili-language.
In entrambe le prove si edita lo stesso identico testo di prova e si pubblica l’articolo; dopo bisogna andare a vedere come è stato scritto nel database, poi visualizzare quel post nel browser per vedere come viene stampato, cioè il codice sorgente.
Tutto questo ti aiuterà a capire dove i paragrafi spariscono, confrontando come WordPress di default ha fatto (nel db e nel sorgente) e come la tua installazione si differenzia dal riferimento. Il problema può avvenire salvando il post, quindi lo vedrai nel database, oppure nel momento in cui il post viene estratto dal database e fornito al browser; in questo caso la differenza con il riferimento si noterà nel sorgente.
-
25 Luglio 2012 alle 20:29 #96818peppe01Partecipante
San Pietroburgo, grazie del consiglio, sto avviando la procedura che mi hai consigliato, per amor del vero, perché in ogni caso tra le soluzioni che ho testato per il multiligue al momento xili-language mi sembra sia quella che funziona meglio, non so se la smantellerei in ogni caso.
-
26 Luglio 2012 alle 0:32 #96826peppe01Partecipante
San Pietroburgo, ho installato un wordpress nuovo su un hosting diverso, 3.4.1 e il tema è il twentyeleven, nessun plugin installato, l’editor toglie i paragrafi. Quindi non so se serve effettivamente fare le altre prove, devo aggiungere che ho provato anche con il tema twenty ten, e si verifica la stessa cosa, è sufficente passare dall’editor html all’edito visuale. Quindi direi wordpress applica dei filtri che modificano i contenuti degli articoli.
A margine posso aggiungere che ho anche provato da inserire lo short code necessario al plugin wp-slides per comparire nell’articolo, nel wp base senza plugin, nulla gli accade, nel wp con il plugin attivato compare il tag <tt>[wp-slidesjs category_id=14]</tt>. Quindi credo che i plugin in ogni caso possono influire sul contenuto degli articoli indipendentemente dall’editor.
Al momento la soluzione migliore che ho trovato è il plugin Advanced TinyMCE Config che permette di configurare l’editor ed impostare wpautop a true o false.
-
26 Luglio 2012 alle 11:33 #96834San PietroburgoPartecipante
Non ho il tempo di fare le stesse prove in locale, però dovresti guardare dove esattamente spariscono, a schermo nell’editor e/o anche nel database?
Con WordPress 3.2.x ed il tema TwentyEleven è stato introdotto HTML5 ed i paragrafi alle immagini vengono volutamente tolti. In molti temi la funzione è nel file functions.php od equivalente (loop.php ad esempio) ed è questa o simile:
function filter_ptags_on_images($content){
return preg_replace('@/@<p>@s*(<a@>)?@s*(<im@g /@>)@s*(<@/@a>)?@s*</p>/iU', '123', $content);
}
add_filter('the_content', 'filter_ptags_on_images');</@a>Cercala e se presente commentala per fermarla (le @ presenti sopra le ho dovute aggiungere per riuscire a postare il codice).
-
26 Luglio 2012 alle 12:22 #96836peppe01Partecipante
Se scrivo con l’editor html i paragrafi non sparisono e li ritrovo intatti nel database, invece se inserisco i paragrafi in html e poi passo all’editor visuale, spariscono all’istante, e nell’articolo nel database non ce ne è traccia.
Più tardi controllo anche function.php
-
26 Luglio 2012 alle 22:25 #96846peppe01Partecipante
San Pietroburgo ho effettuato una ricerca accurata e non ho trovato filter_ptags_on_images da nessuna parte nei file di wp.
In ogni caso direi che per il mio problema il caso è chiuso, l’editor visuale rimuove i paragrafi, il plugin Advanced TinyMCE Config funziona bene e corregge la cosa, ho rimesso tutto a posto com’era nel file wp-includes/class-wp-editor.php che all’inizio avevo corretto per risolvere il problema, il plugin fa la stessa cosa risolvendo il problema senza correre rischi
grazie a tutti
-
-
AutorePost
- Devi essere connesso per rispondere a questo topic.