Bilal
Bilal

Reputation: 2673

how to remove read more when full text is on in wordpress?

the code looks like this

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

there is an option in wp-admin>settings>reading>For each article in a feed, show if this is set to full text the excerpt() must return full length article instead of specified length.

how to do this?

Upvotes: 0

Views: 160

Answers (1)

Alex Lane
Alex Lane

Reputation: 206

Good question! The answer is simple: write your own function!

Open up functions.php in your favorite editor and mash random buttons on your keyboard until you get something like this:

function my_awesome_excerpt ($post_id = false, $full = false, $length = 22) {
    if (!$post_id) global $post;
    else $post = get_post($post_id);

    $text = $post->post_content;

    if ($full) return $text;

    else {
        $text_array = explode(' ', $text);
        $return_string = array();
        for ($i = 0; $i <= $length; $i++)
            array_push($return_string, $text_array[$i]);

        $new_awesome_string = '<p>';
        $new_awesome_string .= implode(' ', $return_string);
        $new_awesome_string .= '</p><p class="readmore">';
        $new_awesome_string .= '<a href="' . get_permalink($post_id) . '">';
        $new_awesome_string .= 'Read More' . '</a></p>';

        return $new_awesome_string;
    }
}

Now, you're ready for the cool part. Once you're in your loop, you can write out some magic like this:

echo my_awesome_excerpt();

and it will automagically spit out an excerpt. It's using the global post variable and everything! You can even use it outside of the loop:

echo my_awesome_excerpt($cpt->ID, 22);

and set your own special length!

Or maybe you just know in your heart that it's not worth it, you just want to show the whole thing. How's that look?

Inside the loop, you're going to have to give it a post ID, sorry about that.

echo my_awesome_script($post->ID, false);

I hope this helps. Have a great day!

Upvotes: 1

Related Questions