php syntax slightly wrong. adding read more with title to auto excerpt (3 posts)

  1. mgason
    Posted 3 years ago #

    I just can't seem to get this line right. I think I am awfully close. 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. It works fine without my attempt to add the post title after Continue Reading.

    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'); 
  2. jmahonyrep
    Posted 3 years ago #

    You had a ' in the wrong place.

    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');
  3. mgason
    Posted 3 years ago #

    Thanks so much. I figured I had one wrong and I tried changing them around, obviously I am no PHP expert. It was the first ' which I did not change because it was from the example I copied not what I was adding. The code I copied was wrong, not my addition :-0

Topic Closed

This topic has been closed to new replies.

About this Topic