NARAYAN CHANGDER
NARAYAN CHANGDER

Reputation: 319

Wordpress do_shortcode() with post_content

I want to make the title of any post from post content. So, I made the following in functions.php

 function my_title($title)   
 {  
    global $post;       
    // Do whatever here with your title...  
    $content = $post->post_content;
    print $content;       

    $title =$content.  $post->post_title . ' | ' .  
    get_bloginfo('name');     

    return $title;  
}  

It prints shortcode inside post content but if i apply $content = do_shortcode( $content ); it does not produce the actual post content. When i applied $content = do_shortcode( $content ); website hanged. Let me know how to use $content = do_shortcode( $content ); inside this function so that title can be changed.

Upvotes: 0

Views: 2260

Answers (1)

Sudharshan Nair
Sudharshan Nair

Reputation: 1267

Can you try this with wp_filter_nohtml_kses. I guess your html o/p is causing the issue

$content = $post->post_content;
$content = wp_filter_nohtml_kses( $content ); // this wp_filter_nohtml_kses indicates strip_tags
$content = do_shortcode( $content );

or

echo do_shortcode(get_post_field('post_content', $post->id));

Upvotes: 1

Related Questions