Remove hook get_post_excerpt được add trong class
https://topvietnamlist.com
/**
* Get Post Loop Excerpt
*
* @param array $attributes Block Attributes.
*/
function get_post_excerpt_custom( $attributes ) {
if ( isset( $attributes['displayExcerpt'] ) && true === $attributes['displayExcerpt'] ) {
$excerpt = get_the_excerpt();
if ( isset( $attributes['excerptCustomLength'] ) && true === $attributes['excerptCustomLength'] ) {
// If excerpt_length is less than our custom length, change it for our call, then revert
$excerpt_length = apply_filters( 'excerpt_length', 55 );
if ( $excerpt_length < $attributes['excerptLength'] ) {
add_filter(
'excerpt_length',
function ( $length ) use ( $attributes ) {//phpcs:ignore
return $attributes['excerptLength'];
},
999
);
$excerpt = get_the_excerpt();
add_filter(
'excerpt_length',
function ( $length ) use ( $excerpt_length ) {//phpcs:ignore
return $excerpt_length;
},
999
);
}
$words = explode( ' ', $excerpt );
if ( count( $words ) > $attributes['excerptLength'] ) {
$excerpt = rtrim( implode( ' ', array_slice( $words, 0, $attributes['excerptLength'] ) ), '.' ) . __( '<a href='.get_the_permalink().' class="span-read-more"> ...read more</a>', 'kadence-blocks-pro' );
}
}
echo $excerpt;
}
}
add_action('init', function() {
global $wp_filter;
if ( isset($wp_filter['kadence_blocks_post_loop_content']) ) {
foreach ($wp_filter['kadence_blocks_post_loop_content']->callbacks as $priority => $callbacks) {
foreach ($callbacks as $key => $callback) {
if ( is_array($callback['function']) ) {
$object = $callback['function'][0];
$method = $callback['function'][1];
if ( is_object($object) && get_class($object) === 'Kadence_Blocks_Pro_Postgrid_Block' && $method === 'get_post_excerpt') {
remove_action('kadence_blocks_post_loop_content', array($object, 'get_post_excerpt'),$priority);
}
}
}
}
}
}, 99);
add_action( 'kadence_blocks_post_loop_content', 'get_post_excerpt_custom', 21 );✅ Cách chuẩn để remove action
✔️ Cách 1: Remove sau khi plugin load (khuyên dùng)
💡 Giải thích
🚀 Cách 2 (clean hơn nếu biết hook khởi tạo class)
⚠️ Lưu ý quan trọng
🎯 Bonus: Override luôn function (nếu cần custom)
Nếu bạn muốn mình tối ưu hơn nữa
PreviousChú ý các tham số của wp-login.php, wp-login.php?action=register ... (ok)NextCách sử dụng MU Plugin để ghi đè class 🐷
Last updated