Notices on the front-end

I am reposting. As my last questions wasn’t famous.

My users are submitting custom post types (projects) from the frontend. How do I display notices (such as the one displayed on admin board) to the front end for when the user performs an action, example edit a post.

I know there are hooks for update/submit (post_updated_messages…) but those do not display anything on the frontend.

I tried putting the following but it doesn’t work:

add_filter('post_updated','alert_user');

function alert_user()
{
add_action('display_message','prepare_text');
}

function prepare_text(){
return 'You did it!';
}

in my theme I have

do_action('display_message');

It doesn’t work as prepare_text is never hooked to display_message!

Any help?

Thanks

Solutions Collecting From Web of "Notices on the front-end"

You could filter the_content:

add_action( 'post_updated', 'wpse105892_add_message', 10 );
function wpse105892_add_message() {
    add_filter( 'the_content', 'wpse105892_display_message' );
}

function wpse105892_display_message( $content ) {
    // remove the action once it's run
    remove_action( 'post_updated', 'wpse105892_add_message', 11 );

    $content = "<div class='your-message'>You did it!</div>\n\n" . $content;
    return $content;
}