Can not get the syntax right, excerpt more with post title

Hi,
I just can’t seem to get this line right. I think I am awfully close. I am copy change and hope kind of PHP person! My code editor tells me I have a syntax error.

return <a 'href="'. get_permalink($post->ID) . '">' . 'Continue Reading:'. get_the_title() . '</a>');

Just in case here is the whole function

function new_excerpt_more($more) {
       global $post;
	return <a 'href="'. get_permalink($post->ID) . '">' . 'Continue Reading:'. get_the_title() . '</a>';
}
add_filter('excerpt_more', 'new_excerpt_more');

I think your problem is probably the “get_permalink($post->ID)” section. I’m not 100% sure what you’re trying to achieve but I think it’s just build a link that directs to a specifc post right?

I achieved something similar using shortcodes like so:


add_shortcode("addlink", "add_link");  //Create [addlink] shortcode to generate button

function settings_url() {
	$settings_url = "/my-settings/";
	return $settings_url;
}

//  Create shortcode to build link to register a home patient to current post
function add_link($content = null) {
	$url = site_url() . settings_url() . "register";  //Set base url for form
	$parent = "&home_id=" . get_the_ID();  //Set variable to Wordpress function for current post id
	$assembled_url = $url .  $parent;  //Build full url
	$url_class = "iframeFancybox3 form-button";  //Classes to be applied to url
	$button_text = "Add";  //Text visable on button
	$adddoclink = '<a href="'.$assembled_url.'" class="'.$url_class.'">'.$button_text.'</a>';  //Assemble complete link
	return $addlink;  //Return complete link
}


If that’s any use. I tried doing it the way you are and it wouldn’t resolve the php so I wound up doing it like this and it’s working perfectly for loads of them.

Thanks for the input. I am trying to replace the default […] that is at the end of a automatic post excerpt, when there is a list of them on the blog page.
The code below does work, I just can’t seem to add the title after Continue Reading.

function new_excerpt_more($more) {
       global $post;
	return ' <a href="'. get_permalink($post->ID) . '">Continue reading </a>';
}
add_filter('excerpt_more', 'new_excerpt_more');

Shouldn’t get_the_title() be passed a parameter? Something like get_the_title($post->ID) perhaps?

May sound stupid but have you tried surrounding the Continue Reading bit with " marks?

If you look at the code I posted last time, I set the link text in the variable “$button-text”. If you’re having trouble try assembling it in another variable and then just call the variable as the text. That’s what I always do if something isn’t working, try breaking it down further and set it away from the main bit. Nested double and single quotes are a real pain so I’d try that.

So maybe:


function new_excerpt_more($more) { 
       global $post; 
       $text = "'Continue reading ' .  get_the_title($post->ID)".
    return ' <a href="'. get_permalink($post->ID) . '">$test</a>'; 
} 
add_filter('excerpt_more', 'new_excerpt_more');  

Beyond that I dunno I’m afraid bud.

Hi,
your idea of using a variable for the title is good. Also you are right you have to use the ID in the title if not using it in the loop.
If you look at the color in your code you can see it still has some syntax problems line 3 and 4, oh how I hate the evil ’ ’
I got it to this but the 4th line still says syntax error

function new_excerpt_more($more) {
       global $post;
       $text = 'Continue reading ' .  get_the_title($post->ID);
    return '<a href="' . get_permalink($post->ID) . '"> ' . $text '</a>';
}
add_filter('excerpt_more', 'new_excerpt_more');

Thanks for a good try anyway :wink:

Yeah, sorry about that I just rattled it out for a quick example and didn’t check it properly.

Have you managed to get anywhere with this then? Also I’m sure you don’t need the . before the variable, surely just “$text” would be enough?

Finally this works in case anyone should come across this

function new_excerpt_more($more) {
       global $post;
    return '<a href="'. get_permalink($post->ID) . '">' . ' ..Continue Reading  '. get_the_title($post->ID) . '</a>';
}
add_filter('excerpt_more', 'new_excerpt_more');

It was the first ’ which was here <a 'href instead of here '<a href

Glad you got it sorted bud :slight_smile: