habib
habib

Reputation: 63

How to apply wordpress filter function only on post title

I am new in wordpress plugin development.I want to customize wordpress post title not page title.I wrote this code.

add_filter( 'the_title', 'change_title', 10, 1 );
function change_title( $title ) {
    $title = 'Posted: ' . $title;
    return $title;  
}

It changes both (page and post) title.How can i apply this filter only on post title ?

Upvotes: 0

Views: 3455

Answers (1)

Kazem Pooshgan
Kazem Pooshgan

Reputation: 50

add_filter('the_title', 'change_title', 10, 2);

function change_title($title, $id)
{
    if (get_post_type($id) == "post") $title = 'Posted: ' . $title;
    return $title;
}

enjoy

Upvotes: 2

Related Questions