2025 the latest dry tutorial WordPress anti-gathering best method to share

To prevent the site from being malicious collection, then you need to understand most of the collection methods and rules, so that you can do the opposite of shielding and anti-acquisition, sometimes we work hard to write some of the articles or a large number of article content to become someone else's dowry, while others collect but also increase the burden on the server, think about it is not worth it ah.

20024 the latest dry tutorial WordPress anti-gathering best method to share

The reason why I decided to do this anti-acquisition idea for a long time, because some time ago there is a website constantly changing IP to collect our Q&A content, I disable an IP, he changed an IP, I later blocked all the IP segments in that area, which is basically to the end. I'm too busy to spend all my time looking at server IPs and blocking IPs every day, right?

So finally made up his mind to do this thing, previously wanted to randomize the content of the WordPress text to insert the words of the site's name, and then hidden through the internal chain style, but so that others can still be captured in the content of the past, so there is a delay in doing so, and then suddenly reacted to the collection of the most important is the collection of the rules, and want to better capture the need to get to the list of articles, and the list of articles. This is now very good to do.

Simply to popularize, the collection of most people are based on the article columns and lists to get the collection of article URL links, so the most important thing is to turn the page, which is almost all the site to expose all the articles of the site in a way, then the simplest solution is to make the site list can not be endless page, so that even if you can collect dozens of content, but also can not be the entire station's content have been collected away.

 

//WordPress Disable Page Flip Blocker/Anti-Capture
add_filter('pre_get_posts','fanly_basic_query_posts');
function fanly_basic_query_posts($wp_query) {
	if($wp_query->is_admin || !$wp_query->is_main_query()) return;
	if ($wp_query->is_home || $wp_query->is_archive || $wp_query->is_search) {
		$paged = 10;//Displays 404 after 10 pages.
		if($paged && $wp_query->get('paged') > $paged){
			//404 page
			$wp_query->set_404();
			status_header(404);
			nocache_headers();
			include(get_query_template('404'));// Need 404.php for theme
			die();
			//404 page
		}
	}
}

 

If you need to specify the ID classification you can modify it like this

add_filter('pre_get_posts', 'fanly_basic_query_posts');

function fanly_basic_query_posts($wp_query) {
    if ($wp_query->is_admin || !$wp_query->is_main_query()) return;

    // Specify an array of category IDs
    $specified_category_ids = array(24172, 24173, 24192, 24188, 24193, 24191, 24187, 24190, 24189, 24186, 24184, 24182, 24183, 24180, 24181, 24185, 24050, 24179, 24171, 24175, 24176, 24174, 24177, 4, 192, 195, 199, 193);

    if ($wp_query->is_category && in_array($wp_query->get_queried_object_id(), $specified_category_ids)) {
        $paged = 10; // 404 after 10 pages in a given category.
        if ($paged && $wp_query->get('paged') > $paged) {
            // 404 page
            $wp_query->set_404();
            status_header(404);
            nocache_headers();
            include(get_query_template('404')); // Need 404.php for theme
            die();
            // 404 page
        }
    }
}

 

Tutorial expansion, this do the task of customer website paging, recorded, you can ignore this code.

 If the current category is the specified category, only pagination from 1 to 10 is displayed.

function mo_paging() {
    $p = 3;
    global $wp_query, $paged;
    $max_page = $wp_query->max_num_pages;

    // Array of assigned category IDs
    $specified_category_ids = array(24172, 24173, 24192, 24188, 24193, 24191, 24187, 24190, 24189, 24186, 24184, 24182, 24183, 24180, 24181, 24185, 24050, 24179, 24171, 24175, 24176, 24174, 24177, 4, 192, 195, 199, 193);

    echo '
    '; if (empty($paged)) $paged = 1; echo '
  • '; previous_posts_link('Previous'); echo '
  • '
    ; // If the current category is the specified category, only pagination from 1 to 10 is displayed if (is_category($specified_category_ids)) { for ($i = 1; $i <= 10; $i++) { $i == $paged ? print "
  • {$i}
  • "
    : _paging_link($i); } echo '
  • Total 10 Pages
  • '
    ; // Next echo '
  • '; next_posts_link('Next Page'); echo '
  • '
    ; } else { // Pagination by default if ($paged > $p + 1) _paging_link(1, '
  • Page 1
  • '
    ); for ($i = $paged - $p; $i <= $paged + $p; $i++) { if ($i > 0 && $i <= $max_page) $i == $paged ? print "
  • {$i}
  • "
    : _paging_link($i); } echo '
  • Total ' . $max_page . ' page
  • '
    ; // Next echo '
  • '; next_posts_link('Next Page'); echo '
  • '
    ; } echo '
'
; } function _paging_link($i, $title = '') { if ($title == '') $title = "No. {$i} Page"; echo "
  • <a href='", esc_html(get_pagenum_link($i)), "'>{$i}
  • "
    ; }

     

    Copy the above code and put it into the functions.php file of the current theme, then you can realize that the 404 page of the WordPress theme will be called when the WordPress page exceeds 10 pages, and you can customize the number of pages by modifying the value of the paged parameter of the code.

    The code will take effect on all list pages, home page, article archive (category, tag, date), search page, etc. are treated equally, you can also add judgments according to their own needs, according to different lists to do different restrictions, here will not expand the share.

    Also if your translation is using get_next_posts_link(string $label=null, int $max_page) to page the next page, you can also set the max page to avoid a page-flipping dead link.

    Don't look at the above lines of code, in fact, the 404 page that the whole paragraph can be used directly to jump to the home page, or even directly use die end, I share here just for the sake of the beautiful end of the 404 page only.

    If in order to better prevent WordPress is collected, then you can also feed, sitemap sitemap, etc. to do shielding, because WordPress page turnover page parameters so you can also server shield path way. So that the collection can not get a complete list of links to the site can basically prevent a large part of the collection.

    As we WordPress exchange group people are asking about specific columns custom shield page how to do, so it will come back to a little bit of trimming, a little code in the number of "10" is customizable, according to the back of the notes can be modified.

     

    add_filter('pre_get_posts', 'fanly_basic_query_posts');
    function fanly_basic_query_posts($wp_query) {
        if ($wp_query->is_admin || !$wp_query->is_main_query()) return;
    
        // Get the current page number
        $paged = $wp_query->get('paged');
    
        // Specify the category ID and the corresponding page limit
        $category_limits = array(
            1 => 2,  // The page limit for Category ID 2 is 2 pages.
            // You can add more category IDs and their page limits here
            // For example, 3 => 5, which means that category ID 3 has a page limit of 5.
        );
    
        // Judgment conditions, if any of the following conditions are met and the number of current pages exceeds the specified number of pages, then a 404 page is displayed.
        if (
            ($wp_query->is_home && $paged > 10) // If it's the first page and the number of pages is greater than 10
            || ($wp_query->is_category && isset($category_limits[$wp_query->get_queried_object_id()]) && $paged > $category_limits[$wp_query->get_queried_object_id()] && $paged > 2) // If it is the specified category and the number of pages is greater than the specified value and greater than 2
            || ($wp_query->is_tag && $paged > 10) // If it's a tabbed page and the number of pages is greater than 10
            || ($wp_query->is_author && $paged > 10) // If it's an author page and the number of pages is greater than 10
            || ($wp_query->is_archive && $paged > 10) // If it's an archive page and the number of pages is greater than 10
            || ($wp_query->is_search && $paged > 2) // If it's a search page and the number of pages is greater than 10
        ) {
            $wp_query->set_404();
            status_header(404);
            nocache_headers();
            include(get_query_template('404')); 
            die();
        }
    }
    
    

    Well, the above is for WordPress anti-gathering to provide a piece of code, I feel the most practical and best way to prevent the collection of ideas and solutions. If you encounter website problems, you need secondary development can contact us. WeChat: wxmbxzb

    WordPress Support Team
    WordPress Support Team

    💻 A sincere and meticulous young developer 🎓 specializing in the field of custom foreign trade website development.
    🌟 specializes in WordPress website design customization and full-service development. Our unique advantage is not only proficient in website development technology, but also the international mainstream art design elements 🎨 skillful integration, while developing accurate and effective brand marketing strategy 📈.
    💡 Services covered:
    🔍 WordPress Theme Development for a unique website visual style and user experience.
    💻 WordPress website customization, tailor-made exclusive website according to your foreign trade business needs.
    Whether it's website architecture construction, interface aesthetic design, or brand promotion strategy, we can provide you with one-stop quality solutions to help your foreign trade business stand out on the Internet and step into the global market 🚀.

    Articles: 43

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    Submit your request

    Quote Collection Form

    💥Website Builder | Strengths speak for themselves, not false!

    Treasure, we say, a lot of parties are not happy with their own sites are peers copying homework, which is like you open a store, certainly do not want others to know your sources of supply is a reason, right? So, in order to give customers a full sense of security, we did not put any customer case work on the site of the link ha, this is our protection of customer privacy.

    📌 But if there is a sincere desire to do the site of the boss, or treasure you just want to look at our case, then hurry up to add the contact information of our website, we snappy send you a few look at, the main one sincere!

    If you have not decided to do what style of website, but also simple, you find a few peers of the site sent to us, according to do on the end of the matter. We choose to imitate the site does not mean that no skill, we just can not stand that kind of invalid communication and cumbersome to make people crazy process. Some parties to do a corporate display site, have to find dozens of suppliers to roll, to be honest, no real technology companies will be there to lick the party. We are not the same, we want to be down-to-earth to the customer to make cost-effective, so that customers are satisfied with the site straight pat. Those kneeling work, let those who only play lip service, no technology companies to do it, we do not serve! # Website Development

    # Party A Party B # Rejected Inside Coil

    Contact the WordPress Technical Team

    We look forward to hearing from you.

    Submit your request

    Quote Collection Form