I would like to add an html
element right before the title of the blog posts. The code I'm using is as follows:
function add_html_above_title($title, $post_id) {
if (is_single() && $post_id === get_the_ID()) {
$html = '<div class="custom-html">Custom HTML content above the title</div>';
// Return the HTML element followed by the original title
return $html . $title;
}
return $title;
}
add_filter('the_title', 'add_html_above_title', 10, 2);
However, the problem with this code is that it also alters the titles used in other parts of the blog post template, like the title of the post used in the breadcrumb. How can I target only the main post title and not the other ones? Can't I for example first check if the title I'm going to modify is inside a specific css
class and only then modify it?
Update: The output of debug_backtrace()
ran on functions.php
in the child theme:
functions.php
file of the child theme. How can I edit the output template? I can't figure out which template is powering the single post page as the main theme is too big and files are scattered all over the place.