Forums

[resolved] Displaying the_content until the more tag and stripping html (2 posts)

  1. Devin Price
    Member
    Posted 1 year ago #

    I have a site where I'd like to use the more tag, but I don't want the images I have set at the top of the post to show up.

    For the moment I am hacked something together to strip all the html tags:

    /* Custom Excerpt Function */
    
    function wpt_strip_content_tags($content) {
    	$content = $post->post_content;
    	$content = strip_shortcodes($content);
    	$content = str_replace(']]>', ']]>', $content);
    	$content = strip_tags($content);
    	return $content;
    }

    And here's how it's displayed:

    $excerpt_content = get_the_content('');
    								echo '<p>' . strip_tags($excerpt_content) . '</p>';

    But I'm wondering if there's a simpler way to do this.

  2. Devin Price
    Member
    Posted 1 year ago #

    Okay, think I got this resolved to be more what I wanted:

    function wpt_strip_content_tags($content) {
    	$content = strip_shortcodes($content);
    	$content = str_replace(']]>', ']]>', $content);
    	$content = preg_replace('/<img[^>]+./','',$content);
    	return $content;
    }

    Display:

    $excerpt_content = get_the_content('');
    echo wpt_strip_content_tags($excerpt_content);

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags