Reputation: 12082
I have a custom theme where when I upload an image with caption, the caption shortcode is shown on the page: [caption id="attachment_109"]...
. Using either of WP's default themes, I see no issue. On inspection, WP uses the_content()
, link, so I need to do some stripping. I get my posts with get_page_by_path()
:
<?php
$post = get_page_by_path( $current_page->post_name, OBJECT, 'service' );
// I assume this would work
$content = the_content($post->post_content);
//Blank page:
echo $content;
Echoing $post->post_content
shows the caption shortcode as mentioned above. How to get rid of if it? BTW, I need the caption values.
Upvotes: 1
Views: 225
Reputation: 123
You can get the post content like this
$post = get_post(123); //pass the id of the post
$content = $post->post_content;
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
echo $content;
or
$content=apply_filters('the_content', get_post_field('post_content', 123)); //123 is the post id
after that just strip the shortcode also you can check if the post is having the shortcode in it or not by has_shortcode
Upvotes: 3