1

I get the read more link like this

<?php the_content("Read More"); ?>

I want on the Homepage a different text than on an archive pages.

I can change the text for all read more links in functions.php like this

add_filter( 'the_content_more_link', 'modify_read_more_link' );
function modify_read_more_link() {
return '<a class="more-link" href="' . get_permalink() . '">Your Read More Link Text</a>';
}

but that will change all read more links.

A conditional tag like is_home() in functions.php also doesn't work.

What could do the job?

  • Did you try is_front_page() ? – birgire Apr 11 '15 at 8:50
  • Yes and nothing else works because conditional tags inside the functions.php won't work in this case. – WendiT Apr 11 '15 at 9:18
  • 1
    Any change you're using query_posts that could be messing around with the global main query ? – birgire Apr 11 '15 at 10:02
  • In this loop only $args = array( 'post__not_in' => get_option( 'sticky_posts' ), 'posts_per_page' => 1); . There are some other loops on the page, but I don't know if that matters – WendiT Apr 11 '15 at 23:19
1

It was simpler than I thought. This has solved it.

<?php
add_filter('the_content_more_link', 'modify_read_more_link');
function modify_read_more_link()
{
    return '<a class="more-link" href="' . get_permalink() . '">Your Read More Link Text</a>';
}
the_content("Read More");
?>
  • Please accept your own answer ;-) – Pieter Goosen Apr 8 '16 at 6:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.