Try making the post object accessible using global and use get_permalink($post->ID)
function new_excerpt_more( $more ) {
global $post;
return '<a class="read-more" href="'. get_permalink($post->ID) . '">Custom text</a>';
}
add_filter( 'excerpt_more', 'new_excerpt_more' );
Ensure the code is in your functions.php file.
Related Posts:
- Get excerpt using get_the_excerpt outside a loop
- How can i display the content in plaintext
- How to force excerpts / teasers in the loop
- Exclude filter on front page
- the_excerpt(), get_the_excerpt() and the_content() all killing “the Loop”
- Content/Excerpt length control for a specific loop?
- Can I use both a custom excerpt and a trimmed excerpt?
- Combining the_excerpt with the_content
- the_excerpt not showing posts
- Using get_the_excerpt() Before The Loop
- How to get the excerpt for is_home() outside of the loop isn’t working
- “the_excerpt” in loop just keeps repeating first post?
- Only Show Excerpt After First 3 Posts
- Excerpts not showing on main page
- Excerpt isn’t working or am I missing something?
- to get a little more content after ‘read more’ inside loop
- Limit article to 100 characters. Can’t use the_excerpt…
- Return only content in excerpt field in loop
- How to add excerpt in loop in Twenty Eleven theme?
- Insert image or ad script after 3 posts using the loop
- WooCommerce Product Page Loop – Output All Product Thumbnails
- Is including the loop necessary for page.php? [duplicate]
- Sorting Woocommerce products with numeric titles [closed]
- loop not showing up when using a custom page template
- Using get_term() in functions.php results in Invalid taxonomy error
- Add Infinite Scroll to Ajax Loaded Category Query
- How to add element after every post in the loop, but not the last one
- Check to see if more than one post
- Style first 3 posts differently with a container, then the rest of the posts [closed]
- Loop through all posts in a certain year
- What are the disadvantages of using global variable?
- Better way to display posts from specific categories, in a grid layout
- Loop after page content
- add most viewed post by google analytic in loop [closed]
- Show the page title on blog page
- Sort posts by most recently modified
- How can I make the loop not count special post formats towards the post count?
- How do I order my loop query?
- Orderby my needs in foreach loop like by title or something?
- How to show posts with multiple tags on tag.php?
- Using an ACF field from a page within a post loop?
- How can I paginate this?
- Obtain page data and use regular loop
- How can I load posts starting from, and including, the current post?
- ‘Auto Draft’ Post showing in wordpress loop
- Why does `inclusive` not work in this wordpress loop?
- How do I automate multiple category loops?
- WordPress Blog has an infinite redirect loop
- Stepping through a foreach loop – adding +1 to the end of it so next time it loops it starts on item 2
- ACF – add a group inside a repeater [closed]
- How to create bootstrap grid loop?
- Is it possible to reverse the order of a list of posts pulled from a loop?
- Give each posts in a loop a number in sequence
- Get post offset/posts page offset in single post page (outside the loop)
- First article : single column; Other articles : 2 columns
- How can I access specific posts brought back by query_posts?
- Put multiple custom loops on same page
- Contact information footer
- custom post on homepage
- Multisite foreach loop returning only one result
- Loop is crazy – one row displays wrong count of posts [closed]
- Generating a perfect loop
- I need to display all post in onepage
- WordPress loop not working only on home page, works on all other pages
- Adding a featured image to a foreach WordPress loop
- Hook to main query with filters based on custom fields
- Using has_tag() outside loop
- Getting selection of posts based on loop variables via Ajax
- Why would this code work locally but break online?
- How to create multiple loop in archive page?
- Offset for Loop
- Why does my WP_Query pagination on a custom page.php only loads the homepage?
- WordPress finding posts on 404 page
- Loop keeps showing the same post even when I click on a different one
- Query users and count totals based on meta values
- php loop error for count posts in category
- display post pdf attachments in side bar with link text
- Display all the terms within a custom taxonomy
- Submit form for loop of products of the term with AJAX
- Use the loop to check if DB record exists?
- Split Content and Gallery
- Adding comma to while loop wpquery output
- Search – Check if post is a page on search page
- How can I make this iterative conditional within the Loop work via function?
- Ajax loop and history.js for SEO
- Show all child categories associated to post ID within loop
- Check if excerpt is empty at loop-portfolio
- Recent posts headlines. How to optimize the loop
- Running the Loop outside of WordPress
- how to use custom loop in the_content filter
- Variable not working in sidebar loop
- Twitter bootstrap carousel multiple items in carousel
- Display all existing members
- Change loop to display items in order
- In Loop Output Place Custom Field Content In Between Paragraphs
- Loop doesn’t give the thumbnail the right parent (or class)
- ACF loops false value with repeater and checkbox
- How to get files from loop for zip
- Divide loop into several columns based on post custom field and enable infinite scrolling
- Query Loop Block: possible to restrict just child pages?