top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to redirect Wordpress 404 page using function()?

0 votes
442 views

I want to change a role in my wordpress plugin.

if ( is_admin() && ! is_user_logged_in() && ! defined( 'DOING_AJAX' ) && $pagenow !== 'admin-post.php' ) {
            wp_die( __( 'This has been disabled', 'wp-hide-login' ), 403 );
        }

        $request = parse_url( $_SERVER['REQUEST_URI'] );

When my plugin get the action, Wordpress shows "This has been disabled" under WP default (admin-post.php) page. But I need when my function get assign it's redirect to 404 page.

As like as "This has been disabled" > http://www.example.com/404

posted May 10, 2017 by Kavyashree

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

You can use this code in your function()

<?php
 if ( is_admin() && ! is_user_logged_in() && ! defined( 'DOING_AJAX' ) && $pagenow !== 'admin-post.php' ) 
       {
         global $wp_query;
         $wp_query->set_404();
         status_header( 404 );
         get_template_part( 404 ); 
         exit();
       }
?>
answer May 17, 2017 by Avijit Maity
Similar Questions
0 votes

I want to create a separate custom 404 page for my wordpress site that when 404 error occurs then that page will be display. I create a 404 page but when I tried to test it, the 404 page of the root site appears. Can anybody help me?

0 votes

I want to send a user, logging out of WordPress, to a custom URL.
I used this below code into functions.php in my wordpress theme:

add_filter( 'logout_url', 'my_logout_url' );
    function my_logout_url( $url ) {
       return 'http://yourdomain.com/?a=logout';
    }

But it does not work.
How can I do this?
Many thanks in advance for your help or advice.

0 votes

I need to force HTTPS for my e-commerce site, but when I try, it goes into an HTTPS -> HTTP -> HTTPS loop. I reviewed my .htaccess, by couple of experienced techs but they found no issue on that. I checked my wp_config.php, and nothing there. Where else should I be looking? How would I hunt this down?

0 votes

I want to display all the existing categories in my Wordpress page in the bottom of the content and the selected category will be in bold style, as follows:

For example, for an existing post if I selected category2 of 3 existing, then it show like this

category1 category2 category3

<div class="entry-meta">
<span class="term-links">
<?php foreach ( get_the_terms( $post->ID, 'category') as $term ) : 
?>
<a href="<?php echo esc_url( get_term_link( $term->term_id ) ) 
?>"><span class="<?php echo $term->slug ?>"><?php echo $term->name ?>
</span></a>
<?php endforeach; ?>
</span>

<style>
.term-links .category2 {
display: inline-block;
font-weight:bold;
</style>

In the above code only display the selected category, not showing the all category. How can I do this?

0 votes

I want to disable the message "No result found" during page loading in my Wordpress site.

$search_code = $_POST['search_code'];

global $wpdb;

$helloworld_id = $wpdb->get_var("SELECT s_image FROM search_code WHERE s_code = $search_code");

if (empty($helloworld_id)) { 
echo '<div class="no_results">No results found</div>'; 
}
else 
{ 
?>

<img src="http://igtlaboratories.com/wp-content/uploads/images/<?php echo $helloworld_id; ?>"style="width:200px;height: auto;">

<?php
}
}

I used this code but when page load by default "No result found" visible. How I disable this massage during page load. Any help?

...