Enhancing Divi Blog Module: Customizing the “Read More” Button Text with WordPress Hooks

—

by

in

The Divi theme, known for its adaptability and features, sometimes throws a curveball when it comes to customizing. One such challenge is changing the “Read More” button text in the blog module. Although some suggest using jQuery, our solution would be to use WordPress Hooks.

Understanding the Structure:

In order to implement this customization we will use the “get_text” filter, one of the WordPress Hooks. While exploring Divi’s files, specifically \Divi\includes\builder\module\Blog.php on line 1092, we identified the text’s text-domain as “et_builder,” with the original text being “read more.”

Utilizing WordPress Hooks:

Let’s incorporate this information into our “get_text” filter. It’s crucial to ensure that this modification applies only to archive pages or any other specific pages you intend to target. In our example, we’ve added a condition using is_archive() to achieve this.

function custom_read_more_text( $translated_text, $text, $domain ) {
if ( 'et_builder' === $domain ) {
if ( 'read more' === $text && is_archive() ) {
$translated_text = 'More Information →';
}
}
return $translated_text;
}

add_filter( 'gettext', 'custom_read_more_text', 20, 3 );

Explanation:

In this code snippet, we’ve crafted a function, custom_read_more_text, that checks if the text domain is “et_builder” and if the text being processed is “read more” on an archive page. If these conditions are met, the “More Information →” text replaces the original “read more” text.

Conclusion:

By harnessing the power of WordPress hooks, specifically the “gettext” filter, we’ve successfully customized the “Read More” button text in the Divi blog module. This approach ensures a cleaner and more WordPress-friendly solution to address the limitations posed by the Divi theme.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *