admin管理员组文章数量:1431317
Im trying to add filter but only when the_content is not empty. So I was trying do something like that:
<?php
$thecontent = get_the_content();
if(!empty($thecontent)) {
add_filter('the_content', 'gs_add_img_lazy_markup', 15);
} ?>
but without results. How should I do it propertly?
edit
What I want to do is create one function with two filters, but one this function should be done only when the_content is not empty. Right now I did this:
add_filter('the_content', 'content_image_markup', 15);
function content_image_markup($the_content) {
$thecontent = get_the_content();
if(!empty($thecontent)) {
// function content
}
}
add_filter('acf_the_content', 'acf_content_image_markup', 15);
function acf_content_image_markup($the_content) {
// the same function content what above
}
how to makes this easer?
Im trying to add filter but only when the_content is not empty. So I was trying do something like that:
<?php
$thecontent = get_the_content();
if(!empty($thecontent)) {
add_filter('the_content', 'gs_add_img_lazy_markup', 15);
} ?>
but without results. How should I do it propertly?
edit
What I want to do is create one function with two filters, but one this function should be done only when the_content is not empty. Right now I did this:
add_filter('the_content', 'content_image_markup', 15);
function content_image_markup($the_content) {
$thecontent = get_the_content();
if(!empty($thecontent)) {
// function content
}
}
add_filter('acf_the_content', 'acf_content_image_markup', 15);
function acf_content_image_markup($the_content) {
// the same function content what above
}
how to makes this easer?
Share Improve this question edited Apr 18, 2019 at 19:21 Piotr Milecki asked Apr 18, 2019 at 17:44 Piotr MileckiPiotr Milecki 253 bronze badges 1 |1 Answer
Reset to default 0Based on your edits, you want one function to apply to two different filters. All you need to do is use the same function on both filters. I haven't tested this, but it should work:
function content_image_markup($content) {
if( !empty($content) ) {
// example of changing the content
$content=$content . ' append this to content';
}
return $content
}
add_filter('the_content', 'content_image_markup', 15);
add_filter('acf_the_content', 'content_image_markup', 15);
本文标签: filtersHow to addfilter only when content is not empty
版权声明:本文标题:filters - How to add_filter only when content is not empty? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745572102a2664106.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
gs_add_img_lazy_markup
function. – mrben522 Commented Apr 18, 2019 at 17:57