我正在尝试从特定的帖子类型中删除短代码,在本例中为链接。我在函数中使用了此代码。php,但它从每个帖子类型的\\u内容中删除了短代码。
<?php
function remove_shortcodes( $content )
{
return strip_shortcodes( $content );
}
add_filter( \'the_content\', \'remove_shortcodes\' );
是否可以修改此选项,使其仅从“链接”帖子类型中删除短代码?谢谢
我正在尝试从特定的帖子类型中删除短代码,在本例中为链接。我在函数中使用了此代码。php,但它从每个帖子类型的\\u内容中删除了短代码。
<?php
function remove_shortcodes( $content )
{
return strip_shortcodes( $content );
}
add_filter( \'the_content\', \'remove_shortcodes\' );
是否可以修改此选项,使其仅从“链接”帖子类型中删除短代码?谢谢
您需要使用WordPress Conditional Tags 查询此页面是否为您要针对的自定义帖子类型,然后查询是否为删除快捷码。
未经测试,但您可以尝试以下操作:
function remove_shortcodes( $content ) {
if ( get_post_type() == \'post-type-name\' ) {
return strip_shortcodes( $content );
}
else
return $content;
}
add_filter( \'the_content\', \'remove_shortcodes\' );
这将删除链接柱类型的短代码。也许你想把它和is_main_query
<?php
function remove_shortcodes( $content )
{
if ( \'link\' == get_post_type() ) // change it to the post type you want
return strip_shortcodes( $content );
else
return $content;
}
add_filter( \'the_content\', \'remove_shortcodes\' );
?>
我刚安装了一个全新的Wordpress用于测试,因为我打算刷新我当前的网站。我的一个要求是能够嵌入Gist中的代码。在Wordpress文档之后,较新版本附带了Gist的特定短代码:Gist Shortcode问题是它根本不起作用。我试着简单地将url粘贴在一行上,或者将其包裹在[要点]标签上,但没有任何效果。url只是在帖子中显示为原始文本。我知道有些插件提供了相同的功能,但我真的希望使用Wordpress的内置功能。我的网站已自动托管并安装在Azure网站上,运行PHP 5.4和Wordpress 3