0

I have created the Read more in my posts, but when I add the php tag

<?php the_content(); ?>

...it shows the post content with read more button. I only want to display the button, with no post content.

Here is a picture of my design .Desired design

In the picture, I only display the button without text from the post. How can i do that with WordPress php code?

2 Answers 2

3

You can achieve this with many ways. First thing you need to use

the_excerpt() 

instead of

the_content()

and in your functions.php file you can add this function to return 0 text from post text.

function custom_excerpt_length($length) {
    if (is_home()) {
        return 0;
    }
}

add_filter('excerpt_length', 'custom_excerpt_length');

This code check if this is homepage you can change the condition to met your needs.

3
  • up vote our teacher :)
    – lotfio
    Commented Aug 30, 2017 at 21:03
  • Thanks Mr. Osama, I changed the function and its working but still cant view the full post or the single post while clicking on the read more button, i used the tag ` the_permalink()` but its not working. any suggestion please. Commented Aug 31, 2017 at 1:37
  • show me your code please to see why permalink not work and BTW i give this function so you can use this template in other pages and change the excerpt length as you need that's why i didn't told you to use only the_permalink() Commented Aug 31, 2017 at 9:21
0

If you JUST need the button, there's probably a different way to go about this:

<a href="<?php the_permalink();?>" class="your-button-class">Read More</a>

Only loads what you need (the permalink) and doesn't bother with extra functions, excerpt length, etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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