• Resolved Bloke

    (@bloke)


    All my posts have a gallery short code on the first line. I want to print a post showing the text but use something like a preg replace to remove [gallery] from the result. Can this be done?

    query_posts('cat=10&name=Elvis&posts_per_page=1');	
    
    if (have_posts()) :
    	while (have_posts()) : the_post();
    		echo '<div class="title">' ; the_title(); echo '<br/>';
    the_post_thumbnail(apply_filters('excerpt_thumbnail_size', 'thumbnail'));
    the_content();
    
    	endwhile;
    endif;

Viewing 3 replies - 1 through 3 (of 3 total)
  • something like this??

    query_posts('cat=10&name=Elvis&posts_per_page=1');	
    
    if (have_posts()) :
    	while (have_posts()) : the_post();
    		echo '<div class="title">' ; the_title(); echo '<br/>';
    the_post_thumbnail(apply_filters('excerpt_thumbnail_size', 'thumbnail'));
    $content = get_the_content();
    echo preg_replace ('/\[gallery\]/', '', $content);
    	endwhile;
    endif;
    Thread Starter Bloke

    (@bloke)

    Thanks. I have tried your suggestion and it removed the gallery but leaves this [gallery ids="6997,6998"]

    Thread Starter Bloke

    (@bloke)

    Since everything I needed to remove was between two brackets I tried this and it worked.
    echo preg_replace ('/\[.*\]/', '', $content);

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Printng text of a post but remove some words’ is closed to new replies.