Skip to content

Commit

Permalink
Merge pull request #4205 from Codeinwp/fix/4187
Browse files Browse the repository at this point in the history
fix: disable excerpt more filter when excerpt block is used
  • Loading branch information
preda-bogdan authored Mar 12, 2024
2 parents fa457da + 07f0571 commit 21f55ab
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion inc/views/template_parts.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
class Template_Parts extends Base_View {
use Layout;

/**
* Use to temporary disable excerpt functionality.
*
* @var bool
*/
private $disable_excerpt = false;
/**
* Function that is run after instantiation.
*
Expand All @@ -34,6 +40,25 @@ public function init() {
add_action( 'neve_blog_post_template_part_content', array( $this, 'render_post' ) );
add_filter( 'excerpt_more', array( $this, 'link_excerpt_more' ) );
add_filter( 'the_content_more_link', array( $this, 'link_excerpt_more' ) );
add_filter( 'render_block_data', array( $this, 'temporary_disable_excerpt_more' ), -99, 3 );
}

/**
* Checks if a query block has the excerpt more block added to avoid duplicate read more.
*
* @param array $block_data Block data.
* @param array $block_type Block type.
* @param array $attributes Block attributes.
*
* @return array
*/
public function temporary_disable_excerpt_more( $block_data, $block_type, $attributes ) {

if ( 'core/post-excerpt' === $block_type['blockName'] ) {
$this->disable_excerpt = true;
}
return $block_data;

}

/**
Expand Down Expand Up @@ -211,7 +236,7 @@ protected function post_class( $post_id = null, $additional = '' ) {
$class .= ' nv-non-grid-article';
}
}

// Filter the Core classes for missing components.
$is_thumbnail_inactive = ! in_array( 'thumbnail', $this->get_ordered_components(), true );
if ( $is_thumbnail_inactive ) {
Expand Down Expand Up @@ -417,6 +442,13 @@ private function get_excerpt( $post_id = null ) {
* @return string
*/
public function link_excerpt_more( $moretag, $post_id = null ) {


if ( $this->disable_excerpt ) {
$this->disable_excerpt = false;
return $moretag;
}

$new_moretag = '… ';

if ( $moretag !== ' […]' ) {
Expand Down

0 comments on commit 21f55ab

Please sign in to comment.