• Resolved jurv266

    (@jurv266)


    I wanted to add a read more link instead of the standard [..] to posts. I used the following code which I found in the codex and I placed it in functions.php:

    // Replaces the excerpt "more" text by a link
    function new_excerpt_more($more) {
           global $post;
    	return '<a class="moretag" href="'. get_permalink($post->ID) . '"> Read the full article...</a>';
    }
    add_filter('excerpt_more', 'new_excerpt_more');

    That works fine but when I go to the posts page its displaying the text below at the top left corner of the post page.
    Read the full article..."> Read the full article..."/>

    I can’t really make sense of where that text comes from. No extra code was added except for in functions.php and some CSS to style the link
    CSS code

    .moretag {
    display:block;
    }

Viewing 6 replies - 1 through 6 (of 6 total)
  • might be a formatting issue.

    can you provide a live link to the posts page to illustrate the problem?

    what theme are you using?

    Thread Starter jurv266

    (@jurv266)

    I’m using a custom made theme not made by me so I’m rolling in the deep here with no knowledge of how exactly everything is build.

    Well after digging deeper and deeper I found out that the header.php from the custom template is the problem the texts come from the code <?php echo get_the_excerpt(); ?>

    <meta itemprop="name" content="<?php the_title(); ?>">
        <meta itemprop="description" content="<?php echo get_the_excerpt(); ?>">
    
        <meta property="og:title" content="<?php the_title(); ?>"/>
        <meta property="og:type" content="article"/>
        <meta property="og:url" content="<?php echo esc_url( get_permalink() ) ?>"/>
        <meta property="og:description" content="<?php echo get_the_excerpt(); ?>"/>

    Now I need to figure out what to change exactly to keep the meta data but also use that excerpt button. If anyone has an answer please do let me know if I figure it out myself I’ll share it here.

    in the header file, try and replace any instances of:

    echo get_the_excerpt();

    with:

    echo htmlentities(strip_tags(apply_filters('get_the_excerpt',$text)));

    Thread Starter jurv266

    (@jurv266)

    Amazing that works! The only thing it does but its not a huge deal is show Read the full article… at the very end of the meta tag when I look at the source code in Firefox but I can live with that. Thank you so much!

    alternatively, you can try to add this line before the meta code section in the header:

    remove_filter('excerpt_more', 'new_excerpt_more');

    and this line after the section:

    add_filter('excerpt_more', 'new_excerpt_more');

    Thread Starter jurv266

    (@jurv266)

    Thanks that works like a charm!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘read more instead of excerpt doesn't work correctly’ is closed to new replies.