supprimer les balises <p> du_contenu
-
-
Pourquoi labalise `
`est-elleimportante?Je suppose que leproblème debaseestjuste le style.Dans ce cas,j'imagine qu'une solution CSSest laplus simple.
Why does the `` tag matter? My guess is that basic problem is just the styling. In that case, I imagine that a CSS solution is the easiest.
- 1
- 2013-08-08
- s_ha_dum
-
le
est votre ami.Vous devriez vraiment apprendre à vousen servir.
theis your friend. You should really learn how to use it.
- 0
- 2013-08-09
- westondeboer
-
ces deux commentaires sonttout simplementmauvais.htmlestimportantpour diverses raisons,mais dans ce cas,parce que l'utilisateur demande spécifiquement une solutionpourne pas les utiliser.both of these comments are just bad. html matters for a variety of reasons, but in this case because the user is specifically asking for a solution to not use them.
- 4
- 2018-12-18
- albert
-
11 réponses
- votes
-
- 2018-11-14
Par défaut,WordPress ajoute desbalises deparagraphe aux descriptions de catégories.Arrêtez celaen ajoutant ce qui suit à votrefichier functions.php
// Remove p tags from category description remove_filter('term_description','wpautop');
Simpleet facile (sans code).
Merci
By default, WordPress adds paragraph tags to category descriptions. Stop this by adding the following to your functions.php file
// Remove p tags from category description remove_filter('term_description','wpautop');
Simple and easy (codeless).
Thank you
-
- 2013-12-07
Wordpress ajoute automatiquement lesbalises
<p>
au contenu.Donc,il apparaît lors du chargement du contenu.C'est avec lefiltrewpautop
.Nous allons donc supprimer cefiltrepour letype depublicationimage
uniquement.Vouspouvezgérer celaen ajoutant le code suivant dans lefichierfunctions.php.// Add the filter to manage the p tags add_filter( 'the_content', 'wti_remove_autop_for_image', 0 ); function wti_remove_autop_for_image( $content ) { global $post; // Check for single page and image post type and remove if ( is_single() && $post->post_type == 'image' ) remove_filter('the_content', 'wpautop'); return $content; }
is_single()
vérifie si un seulmessageest affiché.Wordpress automatically ads the
<p>
tags to the content. So it shows up while loading the content. This is with the filterwpautop
. So we will remove this filter for theimage
post type only. You can manage this by adding the following code in functions.php file.// Add the filter to manage the p tags add_filter( 'the_content', 'wti_remove_autop_for_image', 0 ); function wti_remove_autop_for_image( $content ) { global $post; // Check for single page and image post type and remove if ( is_single() && $post->post_type == 'image' ) remove_filter('the_content', 'wpautop'); return $content; }
is_single()
checks if a single post is being displayed. -
- 2013-08-08
Si cetype depublicationest appelé "image",vouspouvez créer unmodèle uniquepourgérer l'affichage dutype depublication uniquement.
Copiez simplement votrefichier 'single.php'et renommez la copie 'single-image.php'.Vouspouvez désormais contrôler uniquement lespublications d'images.Pour supprimer lesbalises,j'aime utiliser lafonction
strip_tags()
.Si vousimprimez le contenu dumessage avecthe_content()
,il applique déjà lefiltre de contenu,enveloppant les lignes dans lesbalises<p>
.Voici unexemple de lafaçon dont vouspourriez obtenir le contenu de votreimage sans lesbalises:
$imageContent = get_the_content(); $stripped = strip_tags($imageContent, '<p> <a>'); //replace <p> and <a> with whatever tags you want to keep after the strip echo $stripped;
J'espère que cela vous aidera!
If this post type is called "image", you can create a single template to handle the display of just the image post type.
Just copy your 'single.php' file and rename the copy 'single-image.php'. Now you can control just the image posts. To strip out tags, I like to use the
strip_tags()
function. If you print the content of the post withthe_content()
it already applies the content filter, wrapping lines in<p>
tags.Here is an example of how you could get the content of your image without the tags:
$imageContent = get_the_content(); $stripped = strip_tags($imageContent, '<p> <a>'); //replace <p> and <a> with whatever tags you want to keep after the strip echo $stripped;
Hope this helps!
-
- 2017-01-12
Ajoutez simplement ci-dessous la ligne de code dans lefichierfunctions.php de votrethème
Pour le contenu:
remove_filter( 'the_content', 'wpautop' );
Pour unextrait
remove_filter( 'the_excerpt', 'wpautop' );
en savoirplus: https://codex.wordpress.org/Function_Reference/wpautop
Simply add below line of code in your theme's functions.php file
For content :
remove_filter( 'the_content', 'wpautop' );
For excerpt
remove_filter( 'the_excerpt', 'wpautop' );
learn more : https://codex.wordpress.org/Function_Reference/wpautop
-
- 2015-06-05
Vouspouvez utiliser
get_the_content()
au lieu dethe_content()
. Celapeut résoudre votreproblèmeet une autre solutionest lamême que celle décritepar @ChittaranjanYou can use
get_the_content()
instead ofthe_content()
. This may solve your problem and another solution is same as described by @Chittaranjan -
- 2017-01-12
Vouspouvez utiliser une classe depublication spécifiquepour le
single-post
ou lesingle-format-standard
et lemasquer comme vous le souhaitez sur une seulepagepour qu'ilgagnecen'estpas un conflitpour d'autresparties du site Web.Exemple de code CSS *
.single-post .entry-content p:empty { display: none; }
Exemple de code CSSpour uneimage auformat depublication spécifique
.single-format-image .entry-content p:empty { display: none; }
You can use specific post class for the
single-post
orsingle-format-standard
and make it hide as you require only in a single page so that it won't be a conflict for other parts of the website.Example CSS Code*
.single-post .entry-content p:empty { display: none; }
Example CSS Code for specific post format Image
.single-format-image .entry-content p:empty { display: none; }
-
Excellente suggestion!Jene savaispas: le vide était une chose!Great suggestion! I didn't know :empty was a thing!
- 0
- 2020-07-10
- Kenton de Jong
-
-
- 2015-06-05
add_filter( 'the_content', 'remove_autop_for_image', 0 ); function remove_autop_for_image( $content ) { global $post; if ( is_singular('image')) remove_filter('the_content', 'wpautop'); return $content; }
Another way to code it based on the solution by @chittaranjan
add_filter( 'the_content', 'remove_autop_for_image', 0 ); function remove_autop_for_image( $content ) { global $post; if ( is_singular('image')) remove_filter('the_content', 'wpautop'); return $content; }
-
- 2017-01-12
mettez ce code dans "style.css" de "Thèmeenfant actif"
p:empty { display: none; }
put this code in "style.css" of "Active child theme"
p:empty { display: none; }
-
+1 `p: vide {affichage: aucun;} ` @ Parthavi-Patel.Ilestbon de lefaire cacher avec un élément vide,car la suppression desfonctionsnativesest unemauvaisepratiquebien quenous ayons une option.+1 `p:empty { display: none; }` @Parthavi-Patel. It's good to make it hide with an empty element is found as removing the native functions is a bad practice though we have an option.
- 1
- 2017-01-12
- Maqk
-
- 2017-09-26
-
- 2017-12-27
Bien que la question ait été répondue,je publie ce qui suitpourplus d'informations.
remove_filter ('the_exceprt', 'wpautop'); remove_filter ('the_content', 'wpautop'); remove_filter('term_description','wpautop');
though the query has been answered, I'm posting the below for further reference.
remove_filter ('the_exceprt', 'wpautop'); remove_filter ('the_content', 'wpautop'); remove_filter('term_description','wpautop');
J'ai unformat depublication Image,et je rencontre unproblème où l'imageestenveloppéepar unebalise
<p>
.Je veuxme débarrasser de cettebalise (enparticulier sur la versionsingle.php
) de cestypes depublication.Commentpuis-jeentrer dans lamiseen forme d'unthèmeet supprimer lesbalises
<p>
,ou créer leformat demon choixpour la sortie de cetype demessage,sans affecter lespublications d'unformat demessage différent?