filters - Auto append text after the title?

admin2025-06-02  9

Original Title -> Original Title - Lorem ipsum

How can I do this with hard code?

I want this to stop people that web scrape my web without giving credit and making money off my posts from their ads

I found something like this

function titlerestriction( $title ) {

    global $post;

    $title              = $post->post_title;
    $restrictedWords    = "word1;word2;word3";
    $restrictedWords    = explode(";", $restrictedWords);

    foreac( $restrictedWords as $restrictedWord ) {
        if( stristr( $title, $restrictedWord ) ) {
            wp_die( __( 'Error: You have used a forbidden word in post title' ) );
        }
    }
}
add_action( 'publish_post', 'titlerestriction' );

but its the opposite of what i need

Original Title -> Original Title - Lorem ipsum

How can I do this with hard code?

I want this to stop people that web scrape my web without giving credit and making money off my posts from their ads

I found something like this

function titlerestriction( $title ) {

    global $post;

    $title              = $post->post_title;
    $restrictedWords    = "word1;word2;word3";
    $restrictedWords    = explode(";", $restrictedWords);

    foreac( $restrictedWords as $restrictedWord ) {
        if( stristr( $title, $restrictedWord ) ) {
            wp_die( __( 'Error: You have used a forbidden word in post title' ) );
        }
    }
}
add_action( 'publish_post', 'titlerestriction' );

but its the opposite of what i need

Share Improve this question edited Mar 11, 2019 at 14:10 Howdy_McGee 20.9k24 gold badges91 silver badges177 bronze badges asked Mar 10, 2019 at 20:59 user159405user159405 2
  • How would adding text to the title prevent scraping exactly? – Jacob Peattie Commented Mar 11, 2019 at 13:07
  • Please keep your questions, answers, and comments, PG. – Howdy_McGee Commented Mar 11, 2019 at 14:11
Add a comment  | 

1 Answer 1

Reset to default 1

If I understand you correctly, then the_title hook should help you. You can assign your filter to it and modify the title as you wish:

add_filter( 'the_title', function( $title, $id ) {
    return $title . ' - Lorem ipsum';
}, 10, 2 );
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748819525a313990.html

最新回复(0)