experiment with adding line breaks in post excerpts
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
0e573099fc
commit
f5790a0b11
@ -30,4 +30,39 @@ function autonomic_theme_scripts() {
|
|||||||
// this is also for block styles
|
// this is also for block styles
|
||||||
wp_enqueue_script( 'autonomic-block-styles', get_theme_file_uri( '/js/block-styles.js' ), array( 'wp-blocks', 'wp-dom-ready', 'wp-edit-post' ), filemtime( get_theme_file_uri( '/js/block-styles.js' ) ));
|
wp_enqueue_script( 'autonomic-block-styles', get_theme_file_uri( '/js/block-styles.js' ), array( 'wp-blocks', 'wp-dom-ready', 'wp-edit-post' ), filemtime( get_theme_file_uri( '/js/block-styles.js' ) ));
|
||||||
}
|
}
|
||||||
add_action( 'enqueue_block_editor_assets', 'autonomic_theme_scripts' );
|
add_action( 'enqueue_block_editor_assets', 'autonomic_theme_scripts' );
|
||||||
|
|
||||||
|
|
||||||
|
// Code for enabling line breaks in post excerpts
|
||||||
|
|
||||||
|
define('EXCERPT_RARELY', '{[}]');
|
||||||
|
define('EXCERPT_BR', nl2br(PHP_EOL));
|
||||||
|
|
||||||
|
function so306588_trim_excerpt_custom($text = '')
|
||||||
|
{
|
||||||
|
add_filter('the_content', 'so306588_trim_excerpt_custom_mark', 6);
|
||||||
|
|
||||||
|
// get through origin filter
|
||||||
|
$text = wp_trim_excerpt($text);
|
||||||
|
|
||||||
|
remove_filter('the_content', 'so306588_trim_excerpt_custom_mark', 6);
|
||||||
|
|
||||||
|
return so306588_trim_excerpt_custom_restore($text);
|
||||||
|
}
|
||||||
|
|
||||||
|
function so306588_trim_excerpt_custom_mark($text)
|
||||||
|
{
|
||||||
|
$text = nl2br($text);
|
||||||
|
return str_replace(EXCERPT_BR, EXCERPT_RARELY, $text);
|
||||||
|
}
|
||||||
|
|
||||||
|
function so306588_trim_excerpt_custom_restore($text)
|
||||||
|
{
|
||||||
|
return str_replace(EXCERPT_RARELY, EXCERPT_BR, $text);
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove default filter
|
||||||
|
remove_filter('get_the_excerpt', 'wp_trim_excerpt');
|
||||||
|
|
||||||
|
// add custom filter
|
||||||
|
add_filter('get_the_excerpt', 'so306588_trim_excerpt_custom');
|
Loading…
Reference in New Issue
Block a user