Home > OS >  How to disable the Wordpress posts access from date paths?
How to disable the Wordpress posts access from date paths?

Time:10-25

My posts are accessible by anyone that uses the url of my website a date path.

How can I disable this feature, so that the only way to access my posts are using the slug?

Example - enter image description here

CodePudding user response:

Here is a simple plugin which can disable listing posts by date. just upload it to your wp-content/plugins, and enable it at admin portal.

disable-date-path.php

<?php
/**
 * Plugin Name: Disable date path
 * Description: Disable date path
 * Author:      Emptyhua
 * Version:     0.1
 */

if (!function_exists('my_disable_date_path')) {
    function my_disable_date_path($query) {
        if (!is_admin() && $query->is_main_query() && $query->is_date) {
            wp_die('Date path disabled.');
        }
    }

    add_action('pre_get_posts', 'my_disable_date_path');
}
  • Related