douling1936 2017-07-21 11:53
浏览 73
已采纳

如何在Wordpress HTML中删除短代码

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.

  • 写回答

1条回答 默认 最新

  • donglie7268 2017-07-21 12:04
    关注

    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(']]>', ']]&gt;', $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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效