0

This code adds the image before all titles on the page.

How do i add one single image before the posts entry title?

function adt_abovetitle($title){

    //Return new title if called inside loop
    if ( in_the_loop() ) {

    $x = do_shortcode('[shortcode id="'. $id . '"]');
        return  $x . $title;    

    } else {
    //Else return regular   
    return $title;
    }
}

add_filter( 'the_title', 'adt_abovetitle');
0

This works fine for me when i test it. I did edit your code as you had a small error in the function name not matching.

Also, you might want to add a conditional tag and wrap the shortcode in a div but otherwise it works.

function adt_abovetitle($title){

    //Return new title if called inside loop
     if ( in_the_loop() && is_singular('post') ) {

    $x = do_shortcode('[shortcode id="'. $id . '"]');
        return  $x . $title;    

    } else {
    //Else return regular   
    return $title;
    }
}

add_filter( 'the_title', 'adt_abovetitle');

You might want to test your else statement as well.

0

The in_the_loop() and is_singular() functions are too heavy and slow down the page load. You just need to edit single.php file in your theme root folder. The code will look like this:

if (has_post_thumbnail()) {
    the_post_thumbnail('full');
}
<h1 class="entry-title"><?php the_title(); ?></h1>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.