If in your template you create a 404.php
all not-found requests will be handled by this template file, and there you can put whatever you want.
Just as example, in the 404.php
file is possible to use something like (it's just a draft):
<?php get_header(); ?>
<h3>
<?php
$slug = get_query_var('name');
if ( $slug ) {
$name = ucwords(str_replace('-', ' ', $slug));
printf( __('Searching for post "%s"?') . ' ', $name );
_e('It does not exists, maybe you can create it.');
} else {
$name = '';
_e('Content you required not exists, maybe you can create it.');
}
?>
<h3>
<div id="user-submitted-posts-wrapper" data-name="<?php echo $name; ?>">
<?php echo do_shortcode('[user-submitted-posts]'); ?>
</div>
<script>
jQuery().ready(function($) {
var name = $('#user-submitted-posts-wrapper').data('name');
if ( name != '') $('.usp-title input').eq(0).value(name);
});
</script>
<?php get_footer(); ?>
The plugin do not support precompiling post title, but you can fill it with jquery.
I inserted the script echoing it directly in the footer for answer semplicity, but is much better register and enqueue it using wp_register_script and wp_equeue_script. You have also ensure that jquery is included in the page, and if you use wp_register_script
you can put jquery in the script dependencies.
Advanced Task
If you want to differentiate some 404 from others you can hook the template_include
filter.
E.g. if you want to show a different 404 if the required post type is 'product', you can use:
add_filter('template_include', 'change_404_template');
function change_404_template($template) {
if ( is_404() && ( get_query_var('post_type') == 'product' ) ) {
return get_stylesheet_directory() . '/my-custom-template-for-not-found.php' ;
}
return $template;
}
Different approach is make a full redirect on 404. This is less performant, because 2 requests are sended to server (one that cause 404 and the second is the redirect) , but in some cases this method can be useful. If you want to follow this way hooks on template_redirect
action:
add_action('template_redirect', 'redirect_404');
function redirect_404() {
if ( is_404() && ( get_query_var('post_type') == 'product') ) ) {
wp_redirect( home_url() ); // I redirect to home, you can redirect wherever you want
exit();
}
}