loop – I’m adding a prefix on post title but I cant do it with a shortcode?

Question

I’m planning to add a every post a title prefix and I want to add it with shortcode. The shortcode contains counting images file inside the post.

This is the shortcode for counting image files

function wpb_demo_shortcode() { 
$images = get_field('imageslist'); 
$total=explode(',', $images);
  echo count($total);
}

add_shortcode('count_files', 'wpb_demo_shortcode');

It works on single post but not on prefix which is on the bottom.

and this is the prefix I’m adding on the functions.php

function shapeSpace_title_prefix($title, $id = null) {

    return  $title;

}
add_filter('the_title', 'shapeSpace_title_prefix', 10, 2);

This is what im thinking about but it shows broken website. The whole website just shows the shortcode and not the contents.

function shapeSpace_title_prefix($title, $id = null) {
    return  $title.do_shortcode("[count_files]");
}
add_filter('the_title', 'shapeSpace_title_prefix', 10, 2);

I tried echo and other things but I can’t return the post titles with that shortcode. Any solution will be appreciated guys. Thanks!

0
user14772091 2 months 2022-05-10T13:27:26-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse