How to Set Excerpt from a Post Link

In this article, we will focus on how to set excerpt from a post link. If you don’t understand what I wanted to say then read the complete article. we will clear the concept of excerpt() function in WordPress. We will cover the basic of excerpt function and give you the example of it.

How to Set Excerpt from a Post Link

So in this article, we will create this (…Read More) Button. it is the really simple button but it is really very functional.

Then what is the meaning of functional?

functional means here we are creating anchor link button which performs like a link but it is nothing than the excerpt function.

So let’s look out the excerpt function.

What is excerpt() and How to Use that?

Excerpt() in the function provided by WordPress. This function is typically used for trimming this post. So what does it mean, if you want to show the sample of the post except using the complete post you can use this excerpt function.

In the above image, you will see how we used the excerpt function. we created an anchor link for the post. So when you click on the read more button you will redirect the complete post.

In the previous article, we had created single.php file. This file was created for generating post layout for the specific post or the complete posts.

So the excerpt function will give you the example of that.

In index.php file just remove  the_content()  function and replace this with  the_excerpt()  function.

When you run your website you will see post will be trimmed. You cannot see the whole post.

Now we are creating the anchor link button in function.php file

import this code into the funciton.php file.

Ok. Now, this code will create the anchor link.

We had created a function called new_excerpt_more() and pass the $more parameter.

In the function, we just return the anchor tag with the read-more class and specify the get_permalink() function with get_the id().

This function will get the id for of the post and pass it to the get_permalink() function.

After that, we call the hook function. which is an add_filter() function and pass the function name in the second parameter.

Now when the_excerpt() function is call the new_excerpt_more function.

If you did not specify any function for excerpt then the default excerpt will execute.

Now we will create Style for this anchor tag.


In the style.css file, we put this code.

That’s it.

Now you will learn How to Set Excerpt from a Post Link.

When you run WordPress site you will see the read more button.

You can add any other thing if want you can add many more things like bootstrap buttons, link and many more.

If you find anything useful then share this article with your friends and family.

Follow us on Youtube, Instagram, and Facebook.

that’s all for this tutorial we will see you in the next article.

Thank You.