最新消息: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)

Plugin to display text before a post

matteradmin5PV0评论

I am trying to display some text before publising post.When i add post i am getting error as

Publishing failed

my code is

function adddata(){

echo "Welcome to my  post!..........";


}


add_action('new_to_publish', 'adddata');

It is not getting displayed

I am trying to display some text before publising post.When i add post i am getting error as

Publishing failed

my code is

function adddata(){

echo "Welcome to my  post!..........";


}


add_action('new_to_publish', 'adddata');

It is not getting displayed

Share Improve this question asked Apr 9, 2019 at 6:10 smrajsmraj 32 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

smraj,

try to use a filter. Use this code snippet. Place this in our theme's functions.php file

add_filter('the_content', 'adddata');

function adddata($content) {

$pre_post_text = 'Welcome to my  post!..........';

// only display this on single post pages
if(is_single() && !is_home()) {
  $content = $pre_post_text.$content;
}
return $content;
}

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far