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);
gs_add_img_lazy_markup
function. – mrben522 Commented Apr 18, 2019 at 17:57