Consenti HTML in estratto
2 risposta
- voti
-
- 2017-05-29
Aggiungipiùtag senecessarioin
$ allowed_tags=...
funzione _20170529_excerpt ($text) { $ raw_excerpt=$text; if (''==$text) { //Recuperail contenuto delpost. $text=get_the_content (''); //Eliminatuttii tag shortcode dal contenuto. $text=strip_shortcodes ($text); $text=apply_filters ('the_content',$text); $text=str_replace (']] >',']] & amp;gt;',$text); $ allowed_tags='& lt; a >,& lt;b >,& lt;br > & lt;i >'; $text=strip_tags ($text,$ allowed_tags); $excerpt_word_count=55;/*** MODIFICA QUESTO. cambiail conteggio delleparole dell'estrattoin qualsiasinumerointero cheti piace. ***/ $excerpt_length=apply_filters ('excerpt_length',$excerpt_word_count); $excerpt_end='[...]';/*** MODIFICA QUESTO. cambia l'estrattoendindin qualcos'altro. ***/ $excerpt_more=apply_filters ('excerpt_more',''. $excerpt_end); $parole=preg_split ("/[\n \ r \t] +/",$text,$excerpt_length + 1,PREG_SPLIT_NO_EMPTY); if (count ($ words) > $excerpt_length) { array_pop ($parole); $text=implode ('',$parole); $testo=$testo. $excerpt_more; } altro { $text=implode ('',$parole); } } return apply_filters ('wp_trim_excerpt',$text,$ raw_excerpt); } Add more tags if you need into
$allowed_tags = ...
function _20170529_excerpt($text) { $raw_excerpt = $text; if ( '' == $text ) { //Retrieve the post content. $text = get_the_content(''); //Delete all shortcode tags from the content. $text = strip_shortcodes( $text ); $text = apply_filters('the_content', $text); $text = str_replace(']]>', ']]>', $text); $allowed_tags = '<a>,<b>,<br><i>'; $text = strip_tags($text, $allowed_tags); $excerpt_word_count = 55; /*** MODIFY THIS. change the excerpt word count to any integer you like.***/ $excerpt_length = apply_filters('excerpt_length', $excerpt_word_count); $excerpt_end = '[...]'; /*** MODIFY THIS. change the excerpt endind to something else.***/ $excerpt_more = apply_filters('excerpt_more', ' ' . $excerpt_end); $words = preg_split("/[\n\r\t ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY); if ( count($words) > $excerpt_length ) { array_pop($words); $text = implode(' ', $words); $text = $text . $excerpt_more; } else { $text = implode(' ', $words); } } return apply_filters('wp_trim_excerpt', $text, $raw_excerpt); }
-
- 2019-04-07
Puoi anche aggiungere uneditor ditesto RTFpergliestratti,aggiungereil codice sottostantenelfile delplugin onelfilefunction.php deltemae saraiin grado di vedere l'editor HTMLpergliestratti. Inoltre,renderà anchegliestrattiin formato HTML. #cheers
L'ho copiato da qualchepartemanon ricordo lafonte. Lo sto usandoin tuttii mieiprogettie funziona.
Modifica: è stato copiato da Aggiunta di uneditor ditesto RTF a Excerpt 2012 risposta difuxia
/** * Sostituisce l'editor diestrattipredefinito con TinyMCE. */ add_action ('add_meta_boxes',array ('T5_Richtext_Excerpt','switch_boxes')); classe T5_Richtext_Excerpt { /** * Sostituisce lemetabox. * * @return void */ funzione staticapubblica switch_boxes () { if (!post_type_supports ($ GLOBALS ['post'] - >post_type,'excerpt')) { ritorno; } remove_meta_box ( 'postexcerpt',//ID '',//Schermo,vuotoper supportaretuttii tipi dipost 'normale'//Contesto ); add_meta_box ( 'postexcerpt2',//Riutilizzare solo 'postexcerpt'nonfunziona. __ ('Excerpt'),//Title array (__CLASS__,'show'),//Visualizza lafunzione null,//Screen,utilizziamotuttigli schermi conmetabox. 'normale',//Contesto 'core',//Priorità ); } /** * Uscitaperilmetabox. * * @param object $post * @return void */ spettacolo difunzioni statichepubbliche ($post) { ? > & lt; label class="screen-reader-text"for="excerpt" > & lt;?php _e ("Estratto") ? > & lt;/label > & lt;?php //Usiamoilnomepredefinito,"excerpt",quindinon dobbiamopreoccuparci //salvataggio,altrifiltriecc. wp_editor ( self :: unescape ($post- >post_excerpt), 'estratto', Vettore ( 'textarea_rows'=> 15, "media_buttons"=> FALSO, "teeny"=> VERO, 'tinymce'=> VERO ) ); } /** * L'estratto di solito è sfuggito. Ciòinterrompe l'editor HTML. * * @param string $ str * @return stringa */ funzione staticapubblica unescape ($ str) { return str_replace ( array ('& amp; lt;','& amp;gt;','& amp; quot;','& amp; amp;','& amp;nbsp;','& amp; amp;nbsp;'), array ('& lt;','>','"','& amp;','',''), $ str ); } } You can add rich text editor for excerpts as well, add below code in plugin file or theme's function.php file and you'll be able to see HTML editor for excerpts. Moreover, it'll render excerpts in HTML format as well. #cheers
I've copied this from somewhere but don't remember the source. I'm using this in my all projects and it's working.
Edit: This was copied from Adding a rich text editor to Excerpt 2012 answer by fuxia
/** * Replaces the default excerpt editor with TinyMCE. */ add_action( 'add_meta_boxes', array ( 'T5_Richtext_Excerpt', 'switch_boxes' ) ); class T5_Richtext_Excerpt { /** * Replaces the meta boxes. * * @return void */ public static function switch_boxes() { if ( ! post_type_supports( $GLOBALS['post']->post_type, 'excerpt' ) ) { return; } remove_meta_box( 'postexcerpt', // ID '', // Screen, empty to support all post types 'normal' // Context ); add_meta_box( 'postexcerpt2', // Reusing just 'postexcerpt' doesn't work. __( 'Excerpt' ), // Title array ( __CLASS__, 'show' ), // Display function null, // Screen, we use all screens with meta boxes. 'normal', // Context 'core', // Priority ); } /** * Output for the meta box. * * @param object $post * @return void */ public static function show( $post ) { ?> <label class="screen-reader-text" for="excerpt"><?php _e( 'Excerpt' ) ?></label> <?php // We use the default name, 'excerpt', so we don’t have to care about // saving, other filters etc. wp_editor( self::unescape( $post->post_excerpt ), 'excerpt', array ( 'textarea_rows' => 15, 'media_buttons' => FALSE, 'teeny' => TRUE, 'tinymce' => TRUE ) ); } /** * The excerpt is escaped usually. This breaks the HTML editor. * * @param string $str * @return string */ public static function unescape( $str ) { return str_replace( array ( '<', '>', '"', '&', ' ', '&nbsp;' ), array ( '<', '>', '"', '&', ' ', ' ' ), $str ); } }
Eccoilmio codiceestratto.
Comefaccio a consentire html come
<a> <b> <i> <br>