I have several wp users who do not insert a title when creating a new post (and custom type post). This means that the permalink is assigned a number as the link. Within the multisite I am developing, this will commonly stop the link from working (the page just refreshes).
I want to show a warning message when the user fails to insert a title on the post before publishing (telling them to insert title AND edit the permalink).
My code so far in the functions.php file:
function check_for_post_title( $post, $ID )
{
$title = $post->post_title;
$permalink = get_permalink( $ID );
if($title =='' || $title == null) {
no_post_title_notice();
} else {
some_post_title_notice();
}
}
add_action( 'publish_post', 'check_for_post_title', 10, 2 );
function no_post_title_notice() {
?>
<div class="notice notice-warning is-dismissible">
<p><?php _e( 'You have not provided a title for your post/page. This will cause the link to be broken. Please revise', 'understrap-post-title' ); ?></p>
</div>
<?php
}
function some_post_title_notice() {
?>
<div class="notice notice-warning is-dismissible">
<p><?php _e( 'I dont know why this message is appearing', 'understrap-post-title' ); ?></p>
</div>
<?php
}
Currently, it's not working and no notices are appearing at the top of the edit post screen after publishing/updating at all. Not sure why it is not firing at all (even the 'else' statement should fire something). What am I doing wrong?
==
not=
for$title
as the first is the operator equals check while the second actual sets the value.