How to set noindex for wordpress pagination. How to exclude posts and categories from WordPress home page, rss feed, categories and archives without plugins Exclude some wordpress categories from pagination

It is well known that pagination generates duplicate pages. This, in turn, can lead to the fact that such a site can “sink” in the search results. In this case, the only way out of this situation is to make it so that search robots do not “see” that there is pagination anywhere on the site.

How to close pagination from indexing?

One of the methods for solving the problem is to add the noindex directive on pagination pages. In the end, they should look like this:

noindex is a special directive used to designate links that are not desirable for indexing by search engines. Bumping into it, the search robot will immediately “understand” that this page does not need to be taken into account. He will simply skip it, which is why it will not be included in the list of those that should be added to the index.

Of all the ways to solve the problem, the most correct and easiest for a WordPress user is a plugin that hides pagination from search engines in two clicks. To do this, just go to the admin section ClearfyPro, then on the tab SEO enable option Noindex for pagination.

In addition to the plugin ClearfyPro, there are other, less convenient, ways to close pagination from robots. Consider the most popular of them.

Method 1. The functions.php file

This method involves adding custom PHP code to your active theme file.

If you don't know how to edit functions.php, then the plugin will help you.

So, at the very end of it, you need to add the following lines:

Function wpschool_noindex_pagination() ( if(is_paged()) echo " "; ); add_action("wp_head", "wpschool_noindex_pagination");

As a result of the code running on pagination pages (starting from the second one), in the section , the above line will be present:

Method 2. Robots.txt file

You can also add noindex for pagination pages via special file robots.txt, which is located in the root directory of your site. It needs to add the following line:

Disallow: */page/

This method is similar to the previous one and gives the same result.

…how to do it? ... in general, not difficult. And if the task is precisely to prohibit the display of one or another category, then we will do this whim in a few minutes.

However, there is a hitch -

…when solving the problem of prohibiting the display of a category in a widget, a gloomy connection arises with it, namely the question: how to set up the display of categories in the right and logical order, but not chaotically!?


…should think hard. …and be clear about your needs. But first things first: and in the final I will give a perfect and ingenious solution for filtering categories ...

using the lightness of the code In the implementation of such prohibitions / permissions of the necessary / unnecessary blog content, it is worth keeping in mind some perspective for the development of your site so as not to encounter another accompanying “surprise” to be or not to be rebuilding the blog in the future - either editing files or replacing plugins.

After all, there is always an alternative: whether to use a plug-in (their number “…like shag…” is not always good), or write the code in the functions file - functions.php (not bad, but does not solve the problem unequivocally)!?

Decide!..

I showed the possible technical insufficiency of a thoughtless start to blogging, but now I propose possible ways of a logical solution:

If you just need to hide a certain category of WordPress widget that is present by default in the belly of any new site, then it's easy.

We open the file about which functions.php was mentioned and somewhere in its final decoding) before the tag?> we prescribe this dashing coded-filter.

// CATEGORY EXCLUSION CODE start function ext_widget_categories($args)( $exclude = "39"; $args["exclude"] = $exclude; return $args; ) add_filter("widget_categories_args","ext_widget_categories"); // RUBRIC EXCLUSION CODE end

The number 39 indicates the category id, which is filtered as a useless bazaar on the site.

You can specify several, separated by commas.

...That's it, one of the questions is closed.

how to hide subcategories in widget

The solution is in the variant of the code just below, which prohibits / allows the display of the names of certain subcategories (child blog entries).

//code for displaying only subcategories of the category with the specified ID=7 start function ext_widget_categories($args)( $args["child_of"] = 7; return $args; ) add_filter("widget_categories_args","ext_widget_categories"); // output code of the only subcategories of the category with the specified ID=7 end

The arguments of these codes can be combined.

Here you go!! we've got full control over the SHOW control in the Categories widget for all of your categories.

… but — however, we say!! It often happens that some time later, after opening the page of the site, one more flaw is found with bitterness: the headings in the sidebar widget are not arranged in a logical order (randomly) - the fastidiousness of developing professionalism, you know.

In this case, you also need to choose from several nice options:

hit the WordPress plugins repository - path: console / plugins / add plugin / ... install / activate ... such a miracle Category Order and Taxonomy Terms Order.

Technical translation of the quote to the plugin:
Order Categories and all taxonomy terms (custom hierarchically) and child terms using drag and drop Sortable Javascript capabilities.
The plugin does not have confusing settings: all you need to do is hover over the “records” on the left in the console, and consider the Taxonomy Order ...

Everything is paradoxically simple: by dragging and dropping the boards, set up the optimal sequence for displaying the names of the existing headings.

The disadvantages of the "plugin" method include the following: you can not prohibit the display of certain categories ...

Therefore, you will have to use the code suggested above, or the plugin shown below ...

Disabling the display of some categories using the NS Category Widget plugin

... let's jump back into the WordPress depository and download the NS Category Widget plugin - this "jerk" will give us another, but more elegant mood to the existing widget "Categories": i.e. - the usual widget should be deleted or hidden in "inactive", and configure this advanced content management option: display/prohibit it.

Go to its settings and set your own rules: by category id, importance of hierarchies, and similar adjustments... It's simple!

The plugin allows you to use many units of widgets at the right levels of pages, to which the settings are individual, unlike the standard “rubricator”, of which you can display at least a dozen, but the settings of the “top” code will apply to everyone: this is the minus of the ability to connect the standard “rubric” widget and the described code at the very beginning of the article... And if you intend to use several variants of category widgets, then you should still download the NS Category Widget plugin.

BUT! in advanced, there is no simpler and more subtle sorting order for categories - this is its minus. Such is the confusion!

The decision is yours...

…if you saw something useful in the article, great!

Hello guys!

Today there will be a technical article that will show you how to exclude records from home page site running WordPress.

You'll also learn how to exclude entire categories, not just specific posts. I will show a lot of options, both with plugins and without them. In general, everything is as always.

In what cases to apply?

The need to exclude some entries, that is, their announcements, from the main page mostly exists on personal blogs, when in addition to large quality articles for a regular audience, it is also worth filling the resource with simple SEO-optimized articles.

Such articles are unlikely to be useful to blog assessors, since they already know all this. In order not to litter the main page with unnecessary announcements, it would be better not to show them. At the same time, they should be added to the site in order to attract a new audience to the resource from search engines. Displaying them is also necessary, but it should be done on the pages of headings and archives so that beginners can find them using the navigation through the sections of the site.

For example, you will not find this article on the main page of my blog on any of their pagination pages (page navigation). At the same time, the announcement of the article is visible in the "Useful" section and on the sitemap page "All Articles".

Without plugin

The way without a plugin is always preferable, but in this case it will not be a priority, since in order to exclude some article, you will have to make changes to the template file that you have installed every time. But still, I will show several different implementations of such a solution, since it is quite realistic that this will suit you.

Below I will give various pieces of code that should be placed in the template's functions.php file.

Exclude specific records by ID

In this option, there is no need to hide entire categories from visibility on the main page, as many people do with various plugins. It is only necessary to add the IDs of the necessary records in the code.

function exclude_post($query) ( if ($query->is_home) ($query->

if ($query -> is_home )

( $query -> // entry (post) id

return $query ; )

On line 3, the numbers 1 and 2 are ID entries that will not be displayed on the home page. You must enter with a comma.

You will find out the ID of the post, page and category in the address bar of the browser when viewing through the editor.

The next option will allow you to exclude entries from the RSS feed.

Exclusion from RSS feed

This code will allow you to exclude announcements from the news feed and not send them to the e-mail database if you use the subscription and announcement service using Feedburner.

function exclude_post($query) ( if ($query->is_feed) ($query->set("post__not_in", array(1, 2));) // post (post) id return $query; ) add_filter(" pre_get_posts","exclude_post");

function exclude_post ( $query ) (

if ($query -> is_feed )

( $query -> set ("post__not_in" , array (1 , 2 ) ) ; ) // entry (post) id

return $query ; )

add_filter ("pre_get_posts" , "exclude_post" ) ;

Adding records in this case and in all others is similar.

Exclusion from rubrics and archives

To exclude posts from category pages, you should use the following code.

function exclude_post($query) ( if ($query->is_category) ($query->set("post__not_in", array(1, 2));) // post (post) id return $query; ) add_filter(" pre_get_posts","exclude_post");

function exclude_post ( $query ) (

if ($query -> is_category )

( $query -> set ("post__not_in" , array (1 , 2 ) ) ; ) // entry (post) id

return $query ; )

add_filter ("pre_get_posts" , "exclude_post" ) ;

This code can be modified and apply an exception from the archives. It is necessary to replace the is_category function with is_archive in the 2nd line.

Search page exclusion

This option may also be required if some records should not be shown to visitors when they use the site search. For example, it can be various news articles that do not carry content on the subject of the site.

function exclude_post($query) ( if ($query->is_search) ($query->set("post__not_in", array(1, 2));) // post (post) id return $query; ) add_filter(" pre_get_posts","exclude_post");

function exclude_post ( $query ) (

if ($query -> is_search )

( $query -> set ("post__not_in" , array (1 , 2 ) ) ; ) // entry (post) id

return $query ; )

add_filter ("pre_get_posts" , "exclude_post" ) ;

Combining multiple options

You can combine all the above options and exclude entries from all types of pages at once or selectively on the necessary ones.

If you take a good look at all the codes, then in the 2nd line you can see a condition in which the page types parameter is set to disable the display of post announcements in them:

  • is_search
  • is_category
  • is_feed
  • is_home

You can combine all options and exclude entries from everywhere or on some pages. For example, for exclusions from categories and the main one, you should place the following code in the functions.php file.

function exclude_post($query) ( if ($query->is_category || ($query->is_home)) ($query->set("post__not_in", array(1, 2));) // post (post) id ) return $query; ) add_filter("pre_get_posts","exclude_post");

function exclude_post ( $query ) (

if ($query -> is_category || ($query -> is_home ) )

( $query -> set ("post__not_in" , array (1 , 2 ) ) ; ) // entry (post) id

return $query ; )

add_filter ("pre_get_posts" , "exclude_post" ) ;

In the 2nd line with the condition (if - if), the parameters for the categories (is_category) or the main one (is_home) are written.

I note that each next parameter is written inside the previous one through 2 vertical lines and is in its brackets. That is, looking at the previous code, you will see that the second condition for the main page is enclosed in its own brackets and is inside the general brackets that wrap the first condition for the categories.

If it is necessary to add some kind of 3rd condition, for example, for archive pages, then it is worth adding it inside the brackets with the condition for the main (is_home) and writing it through 2 vertical lines. In practice, it looks like this.

function exclude_post($query) ( if ($query->is_category || ($query->is_home || ($query->is_archive))) ($query->set("post__not_in", array(1, 2) );) // post (post) id return $query; ) add_filter("pre_get_posts","exclude_post");

function exclude_post ( $query ) (

if ($query -> is_category || ($query -> is_home || ($query -> is_archive ) ) )

( $query -> set ("post__not_in" , array (1 , 2 ) ) ; ) // entry (post) id

return $query ; )

add_filter ("pre_get_posts" , "exclude_post" ) ;

Use the same principle to add other types of pages to exclude.

The next option to exclude entries is to exclude entire headings (categories).

Excluding entire categories

This is very convenient for lazy people when you can simply create some kind of category and add there all the posts that do not require display on certain types of pages.

The code structure is almost the same. It only changes the parameter that specifies the exclusion of a post or category. In the previous cases, the last line was set to the exclude_post record exclusion parameter. In the new code, it should be replaced with exclude_cat.

function exclude_cat($query) ( if ($query->is_home) ($query->set("cat","-1, -2, -3");) // category id return $query; ) add_filter( "pre_get_posts", "exclude_cat");

function exclude_cat ( $query ) (

if ($query -> is_home )

( $query -> set ("cat" , "-1, -2, -3" ) ; ) // category id

return $query ; )

add_filter("pre_get_posts" , "exclude_cat" ) ;

As you can see, the last line has changed and the 3rd line, where the parameter that reads the category ID has been changed. ID in this case is written through a dash, but also through a comma.

The principle of constructing a condition for page types is similar to the options considered earlier, where I showed it using the example of excluding specific posts. It is worth changing the 2nd line, adding the necessary parameters for categories, search, archives or RSS feeds.

So, we have considered methods without a plugin. There is also an option to exclude entries about tags, but now tags are no longer very relevant for 99% of resources. If you need such information, then write in the comments about it, please. I'll add everything right now.

Plugins

Plugins are a more flexible solution to this issue, since when excluding specific entries, there is no need to edit the template file every time. It is worth putting a check-box in the editor of the necessary posts when they are published or after.

If it is worth excluding a special section created for articles that do not require display, then it is better to use one of the codes provided above.

Simply Exclude Plugin

You can download the plugin, both through the WordPress console using the search, and with official WordPress site.

After activation, it will already work and you can not configure it. But still, I recommend making some changes to make working with its functions more pleasant.

After installation and activation, we immediately go to its settings.

Initially, in the plugin settings, everything is set so that when the checkbox is activated (we will consider it a little lower), the necessary pages (posts, categories, pages) will be marked as "allowed for display". Thus, for each type of page, all checkboxes will need to be checked in order for everything to be displayed.

It would be more logical to set such an option when, by activating the checkbox (for example, for the main page), it will mark an article or something else as prohibited for display.

In the settings there are 3 tabs that are designed to configure settings for different types pages:

  • Taxonomies (taxonomies) - setting for the plugin to function in sections WordPress admin panels: headings and tags;
  • Post types (post types) - for post types: articles and pages;
  • Users - settings for users.

Now I will give a screenshot of the settings of the first tab (taxonomy) and explain the parameters that should be set.

  • In the first "Active" settings block, you need to set the "Active" checkbox so that the plugin adds the necessary checkboxes to disable display in categories or any other types of pages;
  • In the second block, put all the parameters opposite the "Exclude" option. It means that when the check-box is enabled in the editor of each page type, it will be hidden from display and new articles will be opened by default for display. If you set the "Include only" parameter, then by checking the checkbox, entries will be opened for display and new articles will be hidden by default. If the second option "Include only" is selected, then after installing the plugin, all entries will be hidden and you will need to set the "Exclude" option;
  • In the "Show / Hide" block, set the "Show" parameter so that the necessary checkboxes are displayed in each type of page in order to be able to disable or enable display.

The same parameters should be set on the other 2 tabs of the Simply Exclude plugin settings.

For example, here is a screenshot of the "Post types" tab.

Of course, you can disable the functioning of some functions, for example, on the first tab, you can deactivate the plugin for categories, if we are not going to exclude all posts of an entire category.

Now about the work of the plugin itself. When you have set the necessary parameters, you can go to the editor of each post type and put checkboxes in front of those pages where you want to exclude their display.

For example, to set the settings for entries, you can go to the editor of the required article or through the All Articles item. And there and there will be the necessary check-boxes. In the editor in the right column there will be a "Simply Exclude" block containing 4 checkboxes for hiding posts and pages:

  • Archives - categories and archives;
  • Feeds - RSS feeds;
  • Front/Home - main;
  • Searches - search.

By checking the required checkbox, you will hide the entry from a certain type of page.

In the WordPress admin panel item "All Posts" next to each article in a new column called "Simply Exclude show" there will also be these 4 checkboxes. The same goes for rubrics. A new column with all checkboxes will be added.


That's all for this plugin. By installing it, you can very quickly and flexibly change the display options for specific posts or entire categories without interfering with the template files.

Plugin Exclude Categories

The plugin is intended only for hiding an entire category from the main page and RSS feed. Since this option does not require much flexibility (I created a rubric once and adds articles there), I recommend implementing the exclusion of an entire rubric by code (see point 2).

You can download the plugin by clicking the button below.

After installing it, go to the settings (Settings - Exclude Category) and select the required category to exclude it from the main page.

Excluding all posts in a category is a common practice. But I see a drawback in it, since the site has to publish a lot of articles to attract search traffic and all of them will be on various issues of the same topic.

And to shove various materials in one heading is not very good.

This option is also often used when actively selling links on the site. The owner creates a rubric and publishes all articles with sales links in it. And this is also not very good, since now webmasters require a link to be placed in one of the main sections of the site so that it is at least a little clickable and has an effect when promoted.

All the guys, on this note, I finish this detailed manual, which should be useful to you if you came to the address for this article. Hope everything goes great for you.

I wish you a great mood and a great day for you. See you.

Sincerely, Konstantin Khmelev!

Today is an article about how you can manually, without using plugins, exclude headings from the main page of a WordPress site.

There are several ways to exclude posts from a specific category from being shown on the main page of your blog site. One of the easiest ways, in my opinion, is to add a small piece of code to the file functions.php. This piece of code will be a kind of filter that will save us from having to change other theme files. With this method, you do not need to spend time redoing the loop for outputting records in a file index.php through query_posts.

So, let's look at an example:

1) Let's say we need to delete entries from a category whose identification number is 4, that is, ID=4. In other words, we need to exclude the display of posts of the category, whose ID is 4, from the main page.

2) We decided on the tasks, we proceed to the implementation - for this we add to the file functions.php the following piece of code:

Function removeFromHome($query) ( if ($query->is_home) ($query->

We save the modified file functions.php and we see that there are no more entries from the ID=4 category on the main page.

From the point of view of WordPress logic, the main page is also any other page that is formed by pagination. Thus, posts from the excluded category ID=4, we will not see on page 2, 3 or 4 and so on.

If this option is not suitable, then you can slightly change the above code to this:

Function removeFromHome($query) ( if ($query->is_home && !(is_paged())) ($query->set("cat","-5");) return $query; ) add_filter("pre_get_posts" ,"removeFromHome");

We save and now on each page, except for the main one, entries from the category with ID=4 will be displayed normally.

Exclude category entries from search results

If you need to exclude category entries from the search results page, then you just need to change is_home on the is_search.

To exclude posts from several categories, you need to list the IDs of these categories separated by commas in the above codes. Let's say you need to exclude categories whose IDs are 3,7,8,9. Then the code will change like this:

Function removeFromFeed($query) ( if ($query->is_feed) ($query->set("cat","-3, -7, -8, -9");) return $query; ) add_filter(" pre_get_posts","removeFromFeed");

Excluding category entries from RSS feed

What to do if you need to exclude posts of a certain category from your RSS feed? And you can do it very simply - use the code below:

Function removeFromFeed($query) ( if ($query->is_feed) ($query->set("cat","-4");) return $query; ) add_filter("pre_get_posts","removeFromFeed");

We save the changes and see that there are no more entries in the feed from the rubric we do not need.

Excluding category entries from the RSS feed and home page

If suddenly you need to make sure that posts from a certain category are not displayed on the main page and in the feed, then you need to use the following code:

Function removeCat($query) ( if ($query->is_feed || ($query->is_home && !(is_paged()))) ($query->set("cat","-3,-7") ;) return $query; ) add_filter("pre_get_posts","removeCat");

In this case, category entries with an ID of 3 will not be shown on the main page and in the RSS feed, but will be shown when other pages are opened.

Changes to file functions.php can be entered anywhere, but without touching the code of another function. The easiest way is to add the code at the end of the file.

On the main page, as well as on the pages of categories, archives and in search results, pagination (also known as pagination) is usually needed. Blogs on WordPress are no exception, they also use pagination, when the results of the output of information are divided into several pages.

Previously, to implement this feature, third-party plugins were used, or special functions that were placed in the file functions.php. However, with the release of WordPress version 4.1, the pagination function was built into the CMS core, and now internal WordPress functions are enough to implement pagination and there is no need to add third-party code or plugins.

I wrote earlier about a similar improvement by WordPress regarding the TITLE tag - https://aboutwordpress.ru/post/wordpress-title/ .

What is pagination

Pagination is the division of information into pages. Also, this concept means the serial numbering of pages, denoted by numbers located at the bottom, top or side of the page.

WP-PageNavi - WordPress pagination plugin

The most popular pagination plugin for WordPress is WP-PageNavi. To be honest, it copes with the task of pagination so well that there is no point in discussing and comparing other plugins.

WordPress Pagination - WP-PageNavi Plugin

wordpress pagination without plugin

In order to make pagination on the site without plugins, we will use the built-in WordPress function the_posts_pagination(). In the place we need to insert the following code (usually these are files index.php, categories.php and the like):

The output of the_posts_pagination() function will be something like this HTML code:

Removing the H2 Header from Pagination

The H2 heading “Post Navigation” immediately catches the eye. Which in most cases has no place on the site. To get rid of it, add the following code to the file functions.php:

/* Remove H2 from pagination */ add_filter("navigation_markup_template", "my_navigation_template", 10, 2); function my_navigation_template($template, $class)( return "

"; }

Setting up pagination pages

By default, the_posts_pagination() displays the first page, the last page, and one page around the current one. All others are replaced with ellipsis. This behavior can be changed with arguments:

  • show_all - show all pages
  • end_size - number of pages at the beginning and end of the list
  • mid_size - number of pages to the left and right of the current page

For example like this:

2, "end_size" => 2,)); ?>

CSS pagination styles

Page-numbers ( padding: 1% 2%; box-shadow: 0 0 10px #ccc; margin: 0 1% 0 0; background: #fff; border-radius: 3px; )

Links to pagination pages with these styles will look like this: