user3433808
user3433808

Reputation: 11

read more excerpt wordpress

I have reviewed the other posts similar to my questions but I must be missing a something. I have added excerpts to my page like so:

[title size="2"]LATEST ARTICLES[/title]
[recent_posts columns="4" number_posts="12" cat_id="" thumbnail="yes"  excerpt="yes" title="yes"] [/recent_posts]

I am trying to do two things

  1. set the length of the excerpt
  2. make it link to the article (not necessarily a read more link the dots are fine)

I have tried to add the excerpt manually to the excerpt area (screen options) for the page but that is not overwritting what Wordpress is pulling from.

in my function.php file I am using

add_filter('the_excerpt', 'do_shortcode');

which works, but when I tried to add additional code below it does not do anything. Do I need to modify anothe rphp file to get this to register?

`enter code here`function new_excerpt_more($more) {
return '<a href="'. get_permalink($post->ID) . '">' . ' read on ..' . '</a>';
}
add_filter('excerpt_more', 'new_excerpt_more');

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

Upvotes: 1

Views: 178

Answers (1)

9ete
9ete

Reputation: 3762

I have achieved your desired result w/ the following code (from the codex):

function custom_excerpt_length( $length ) {
  return 46;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );

function new_excerpt_more( $more ) {
  return ' <a class="read-more" href="'. get_permalink( get_the_ID() ) . '">' . __('Read More', 'your-text-domain') . '</a>';
}
add_filter( 'excerpt_more', 'new_excerpt_more' );

Upvotes: 0

Related Questions