Products
GG网络技术分享 2025-03-18 16:12 4
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.
图片转代码服务由CSDN问答提供
感谢您的意见,我们尽快改进~
功能建议我有一个自定义主题,当我上传带有标题的图像时,页面上会显示标题短代码:< code> [caption id =“attachment_109”] ... </ code>。 使用WP的默认主题之一,我认为没有问题。 在检查时,WP使用 the_content()</ code>,链接 所以我需要做一些剥离。 我的帖子有
get_page_by_path()</ code>:</ p>
&lt;?php $ post = get_page_by_path($ current_page-&gt; post_name, OBJECT,\'service\');
//我认为这样可以工作
$ content = the_content($ post-&gt; post_content);
//空白页:
echo $ content;
< / code> </ pre>
回显 $ post-&gt; post_content </ code>显示如上所述的字幕短代码。 怎么摆脱它? 顺便说一句,我需要标题值。</ p>
</ div>
网友观点:
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
Demand feedback