• Resolved maqtanim

    (@maqtanim)


    Right now to show the ‘Continue Reading …’ in the index page, I’ve to put the <!--more--> tag in each post. Can it be done automatically? I mean I don’t want to put the <!--more--> tag in every post, instead it’ll be done automatically.

Viewing 5 replies - 1 through 5 (of 5 total)
  • On the index.php you could change the_content to the_excerpt.

    do you mean you want to use ‘the_excerpt’ function instead of ‘the_content’?
    https://codex.www.ads-software.com/Function_Reference/the_excerpt

    in your child theme, edit content.php, and change this line:

    <?php if ( is_search() ) : // Only display Excerpts for Search ?>

    for instance to:

    <?php if ( is_search() || is_home() ) : // Only display Excerpts for Search & blog page ?>

    https://codex.www.ads-software.com/Conditional_Tags

    Thread Starter maqtanim

    (@maqtanim)

    Thank you both. I followed the alchymyth‘s suggestion and it worked like a charm. Thanks.

    But is there any way so that I can change the number of the character displayed before ‘Continue Reading …’ button? The default number of character is too less for me. Using to this information, I tried to change the default number of characters by adding the following codes in my child theme’s function.php

    function new_excerpt_length($length) {
    	return 20;
    }
    add_filter('excerpt_length', 'new_excerpt_length');

    But it doesn’t work. (I am not a coder/programmer, so I am not sure whether I did it right).

    it is a bit complicated, because functions.php of the child theme gets executed before the one of the parent theme; thereofre your filter gets overwritten by the original filter for the excerpt length.

    one way to do it:
    add a higher priority to the new filter (https://codex.www.ads-software.com/Function_Reference/add_filter);

    example:

    function new_excerpt_length($length) {
    	return 20;
    }
    add_filter('excerpt_length', 'new_excerpt_length', 11);

    ———–
    different way to do it:

    remove the original filter (after the theme setup) and add your own (you are generally on the right track);

    example:

    add_action( 'after_setup_theme', 'twentyeleven_child_change_excerpt_length' );
    function twentyeleven_child_change_excerpt_length() {
      remove_filter('excerpt_length', 'twentyeleven_excerpt_length' );
      add_filter( 'excerpt_length', 'twentyeleven_child_excerpt_length' );
    }
    function twentyeleven_child_excerpt_length( $length ) {
    	return 20;
    }

    Thread Starter maqtanim

    (@maqtanim)

    Thanks alchymyth. It seems much complicated for me, though I’ll try. Thanks again! ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Twenty Eleven] How can I add "Continue reading…" automatcally?’ is closed to new replies.