Mario Parra
Mario Parra

Reputation: 1554

Conditionally replacing post excerpt "Read More" link

I've written a function to replace WordPress' default "Read More" link for post excerpts with my own, which works, but now I'm trying to replace it with slightly different HTML attributes on a specific page, but I'm getting syntax errors.

Function:

function new_excerpt_more($more) {
  global $post;
    if (is_page( '39' )) {
        return ' [&#8230;]<p><a class="moretag btn btn-primary btn-xl wow bounceIn" href="'. get_permalink($post->ID) . '">Continue reading <span aria-hidden="true">&rarr;</span></a></p>';
        }
    } else {
        return ' [&#8230;]<p><a class="moretag btn btn-primary btn-md" href="'. get_permalink($post->ID) . '">Continue reading <span aria-hidden="true">&rarr;</span></a></p>';
    }
}
add_filter('excerpt_more', 'new_excerpt_more');

Error:

Parse error: syntax error, unexpected 'else' (T_ELSE) in /home/ourcore/public_html/wp-content/themes/portfolio/functions.php on line 7

Any help would be really appreciated. Thanks in advance!

Upvotes: 0

Views: 158

Answers (1)

zanderwar
zanderwar

Reputation: 3730

You had one too many closing curly brackets

function new_excerpt_more($more) {
    global $post;
    if (is_page( '39' )) {
        return ' [&#8230;]<p><a class="moretag btn btn-primary btn-xl wow bounceIn" href="'. get_permalink($post->ID) . '">Continue reading <span aria-hidden="true">&rarr;</span></a></p>';
    }
     else {
        return ' [&#8230;]<p><a class="moretag btn btn-primary btn-md" href="'. get_permalink($post->ID) . '">Continue reading <span aria-hidden="true">&rarr;</span></a></p>';
    }
}
add_filter('excerpt_more', 'new_excerpt_more');

Upvotes: 2

Related Questions