skip to Main Content

I’m creating a page using the Divi theme in my WordPress site.
I want to change the “read more” text in my posts to “Read Article ->”.

I tried to use a tutorial from the elegant themes blog but it didn’t work.

(https://www.elegantthemes.com/blog/tips-tricks/how-to-customize-the-wordpress-read-more-link-text)

How can I change the text using php ? (Not JavaScript)

posts screenshot

Thanks

4

Answers


  1. Are multiple ways to do that:

    1. Using Jquery

    In your WordPress dashboard navigate to Divi>Theme Options>Integration and add code below to the “Body ” field. Note: Make sure the “Enable Body Code” switch is on.

    <script type="text/javascript">
      (function($) {
        $(document).ready(function() {
          var newVal = 'Read Article';
          $('.more-link').html( newVal );
         });
      })(jQuery);
    </script>
    

    2. Adding this code in theme functions.php file

    // Replaces the excerpt "Read More" text by a link
    function new_excerpt_more($more) {
       global $post;
       return '<a class="moretag" href="'. get_permalink($post->ID) . '"> Read the full 
       article...</a>';
    }
    add_filter('excerpt_more', 'new_excerpt_more');
    

    If you are using a Child Theme, the above code will not work without modification if the parent theme has its own filters setting its own “more” link. You will need to use the remove_filter() function to remove the parent’s filters for yours to work. The problem is your functions.php file is loaded before the parent’s functions.php, so at the time of your file’s execution, there is no filter to remove yet, and your remove_filter() code will fail without warning.

    The key is to put your remove_filter() code in a function that executes from an action hook that triggers after the parent theme is loaded. The following code is an example of the additional code needed to get the above code to work from a child theme of the parent Divi theme. You will need to examine your actual parent theme’s code for the correct parameters in the remove_filter() code, they must exactly match the add_filter() parameters used by the parent.

    function child_theme_setup() {
       // override parent theme's 'more' text for excerpts
       remove_filter( 'excerpt_more', 'divi_auto_excerpt_more' ); 
       remove_filter( 'get_the_excerpt', 'divi_custom_excerpt_more' );
    }
    add_action( 'after_setup_theme', 'child_theme_setup' );
    
    Login or Signup to reply.
  2. You are using divi builder. The read more text is in /divi-builder/includes/builder/module/Blog.php at line number 1197

    To change this readmore we can use wordpress gettext filter ( http://codex.wordpress.org/Plugin_API/Filter_Reference/gettext )

    Add the following code to your themes functions.php file and it will solve your issue.

    function my_text_strings( $translated_text, $text, $domain ) {
        switch ( $translated_text ) {
            case 'read more' :
                $translated_text = __( 'read more ->', 'et_builder' );
                break;
        }
        return $translated_text;
    }
    add_filter( 'gettext', 'my_text_strings', 20, 3 );
    

    I already tested the code in one of my wordpress site. its working.

    Login or Signup to reply.
  3. Maybe you can use the plugin Loco Translate

    Login or Signup to reply.
  4. jQuery way with ajax pagination:

    jQuery(document).on('ready ajaxComplete', function() {
        // replace read more text
        var newVal = 'Weiterlesen';
        jQuery(".et_pb_post a.more-link").html(newVal);
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search