-1

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

  • How would adding text to the title prevent scraping exactly? – Jacob Peattie Mar 11 at 13:07
  • Please keep your questions, answers, and comments, PG. – Howdy_McGee Mar 11 at 14:11
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 );

Your Answer

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