get_the_title() doesn’t show any output in backend

Question

I was using an advanced custom field pro plugin and made a block. In the block template, I had to use a get_the_title() function for convenience to automatically show the title of the current post. It works as it’s supposed to in the frontend. But for the backend, it fails to echo any value. For example,

<h2><?php echo get_the_title(); ?> Overview</h2>

This code will only show " Overview" in the backend and in the frontend, it will show "Random-Post Name Overview". Note that this problem occurs in only in some of the built-in WordPress functions. For a custom function like below, which returns the terms of a custom taxonomy it works as it’s supposed to in both frontend and backend.

function character_rarity_sc() {
   foreach((get_terms('character_rarity')) as $terms) {
      return $terms->name;
   }
}

My basic knowledge and intuition suggesting to me that it’s gotta be something with limitations of the function in the frontend. Could be something with the default args also. If that’s the case how can I make it show properly in the backend? Or is there another better function available for this?

0
Fuad Hasan 2 months 0 Answers 16 views 0

Leave an answer