$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>filters - Auto append text after the title?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

filters - Auto append text after the title?

matteradmin10PV0评论

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 );

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far