How to show text only to registered WordPress users. II

Surely you have heard more than once about such a wonderful search engine as Google. I'm guessing you've used it more than once when you wanted to know something. But did you find what you wanted? If you search for answers on Google as often as I do, I think you will find this article useful because it is designed to make your search faster and more efficient. So, first, a little history...

Google is a corruption of the English word "googol", coined by Milton Sirotta, nephew of the American mathematician Edward Kaiser, to denote the number consisting of one and one hundred zeros. Now Google name wears the leader of Internet search engines, developed by Google Inc.

Google occupies more than 70% of the global market, which means that seven out of ten people online turn to its page when searching for information on the Internet. Currently, about 50 million are registered daily. search queries and indexes more than 8 billion web pages. Google can find information in 101 languages. Google at the end of August 2004 consisted of 132 thousand machines located in different parts of the planet.

Google uses intelligent text analysis technology that allows you to search for important and at the same time relevant pages according to your request. For uh that Google analyzes not only the page itself that matches the query, but also the pages that link to it, to determine the value of that page for the purposes of your query. Additionally, Google prefers pages that keywords, you entered are located close to each other.

Google's interface contains a rather complex query language that allows you to limit the scope of your search separate domains, languages, file types, etc. Using some of the operators of this language allows you to make the search process necessary information more flexible and precise. Let's look at some of them.

Logical “AND”:
By default, when you write query words separated by spaces, Google searches for documents that contain all the query words. This corresponds to the AND operator. Those. a space is equivalent to the AND operator.

For example:
Cats dogs parrots zebras
Cats AND dogs AND parrots AND zebras
(both queries are the same)

Logical "OR" (OR):
Written using the OR operator. Please note that the OR operator must be written in capital letters. Relatively recently, it became possible to write a logical “OR” in the form of a vertical bar (|), similar to how it is done in Yandex. Used to search with several options for the required information.

For example:
Dachshunds long-haired OR smooth-haired
Long-haired dachshunds | smooth-haired
(both queries are the same)

Please remember that Google queries are not case sensitive! Those. the queries Greenland Island and Greenland Island will be exactly the same.

Operator "Plus" (+):
There are situations when it is necessary to force a word into the text that may have different spellings. To do this, use the "+" operator before the required word. Suppose if we have a query at Home Alone I, as a result of the query we will have unnecessary information about “Home Alone II”, “Home Alone III” and quite a bit about “Home Alone I”. If we have a query of the form Home Alone +I, the result will be information only about the movie “Home Alone I”.

For example:
Newspaper + Zarya
Bernoulli equation + mathematics

Excluding words from the query. Logical NOT (-):
As you know, information garbage is often encountered when composing a request. To remove it, exclusion operators are used as standard - logical “NOT”. In Google, this operator is represented by a minus sign. Using this operator, you can exclude from search results those pages that contain certain words in the text. Used like the "+" operator before the excluded word.

For example:
Crane well-bird
Dead Souls - novel

Search for an exact phrase (""):
Search exact phrase in practice it is required either to search for the text of a specific work, or to search certain products or companies in which the name or part of the description is a consistently repeated phrase. To cope with this task using Google, you need to enclose the query in quotation marks (meaning double quotes, which are used, for example, to highlight direct speech).

For example:
The work "Quiet Don"
“It was cold outside, although this did not prevent Boris from carrying out his plans”

By the way, Google allows you to enter no more than 32 words into the query bar!

Word truncation (*):
Sometimes you need to look for information about a word combination in which one or more words are unknown. For these purposes, instead of unknown words, the “*” operator is used. Those. "*" - any word or group of words.

For example:
Master and *
Leonardo * Vinci

cache operator:
The search engine stores the version of the text that is indexed by the search spider in a special storage format called a cache. A cached version of a page can be retrieved if original page inaccessible (for example, the server on which it is stored is not working). The cached page is shown as it is stored in the database search engine and is accompanied by a notice at the top of the page stating that this is a cached page. It also contains information about the time the cached version was created. On the page from the cache, the query keywords are highlighted, and each word is highlighted in a different color for user convenience. You can create a request that will immediately return a cached version of a page with a specific address: cache: page_address, where instead of “page_address” is the address of the page saved in the cache. If you need to find any information in a cached page, you need to write a request for this information separated by a space after the page address.

For example:
cache:www.bsd.com
cache:www.knights.ru tournaments

We must remember that there should not be a space between ":" and the page address!

Filetype operator:
As you know, Google indexes not only html pages. If, for example, you needed to find some information in a place other than html type file, you can use the filetype operator, which allows you to search for information in a specific file type (html, pdf, doc, rtf...).

For example:
Specification html filetype:pdf
Essays filetype:rtf

Operator info:
The info operator lets you see the information that Google knows about that page.

For example:
info:www.wiches.ru
info:www.food.healthy.com

Site operator:
This operator limits the search to a specific domain or site. That is, if you make a request: marketing intelligence site:www.acfor-tc.ru, then the results will be obtained from pages containing the words “marketing” and “intelligence” on the site “acfor-tc.ru” and not on others parts of the Internet.

For example:
Music site:www.music.su
Books site:ru

Link operator:
This operator allows you to see all the pages that link to the page for which the request was made. Thus, the request link:www.google.com will return pages that contain links to google.com.

For example:
link:www.ozone.com
Friends link:www.happylife.ru

allintitle operator:
If you start a query with the allintitle operator, which translates as “everything is in the title,” then Google will return texts in which all the words of the query are contained in the titles (inside TITLE tag in HTML).

For example:
allintitle: Free software
allintitle: Download music albums

intitle operator:
Shows pages in which only the word immediately after the intitle operator is contained in the title, and all other query words can be anywhere in the text. Putting the intitle operator before each word of the query is equivalent to using the allintitle operator.

For example:
Programs intitle: Download
intitle: Free intitle: download software

allinurl operator:
If the query begins with the allinurl operator, then the search is limited to those documents in which all the query words are contained only in the page address, that is, in the url.

For example:
allinurl:rus games
allinurl:books fantasy

inurl operator:
The word that is located directly together with the inurl operator will be found only in the address of the Internet page, and the remaining words will be found anywhere in such a page.

For example:
inurl:books download
inurl:games crack

Operator related:
This operator describes pages that are "similar" to some specific page. Thus, the query related:www.google.com will return pages with similar topics to Google.

For example:
related:www.ozone.com
related:www.nnm.ru

define statement:
This operator acts as a kind of explanatory dictionary, which allows you to quickly get the definition of the word that is entered after the operator.

For example:
define: Kangaroo
define: Motherboard

Synonym search operator (~):
If you want to find texts containing not only your keywords, but also their synonyms, then you can use the “~” operator before the word for which you want to find synonyms.

For example:
Types of ~metamorphoses
~Object orientation

Range operator (..):
For those who have to work with numbers, Google has made it possible to search for ranges between numbers. In order to find all pages containing numbers in a certain range “from - to”, you need to put two dots (..) between these extreme values, that is, the range operator.

For example:
Buy a book $100..$150
Population 1913..1935

Here are all the Google query language operators I know. I hope they will somehow make your search process easier. necessary information. In any case, I use them very often and I can say with confidence that when using them I spend significantly less time searching than without them.

Good luck! And may the Force be with you.

Tags: search, operators, Google

Who might find this useful? Hiding content from unregistered users is sometimes necessary in order to expand the user base of your site. Also, if you have, for example paid registration and that part of the material that is sold should be available only to those who purchased access. You can also reverse the method a little and for example, for ordinary visitors show advertising, and those who have entered the site will not see it. In general, everything depends on your imagination and existing needs.

In order to hide, for example, part of the content inside WordPress themes, then you need to enclose the part that will be hidden from unauthorized users in the following code:

This is a condition that says that if the user is logged in, then show the content from the second line, if not, then from the fourth. If you just want to hide and not display any more messages, that is, unauthorized people will see emptiness, then delete the third and fourth lines. It will turn out like this:

Now let’s imagine the situation that I wrote about above, the opposite condition where authorized users should not see, for example, advertising or a login button, etc. The code will be like this:

We have added exclamation mark before the function, which now serves as a negation. Everything inside these codes is added according to PHP rules. If this is difficult for you, then you can break the code and paste in the usual way, for example, if you need to add javascript.

// Here is the advertising code, JavaScript, etc.

This trick can be done with the codes above, that is, instead of echo and content in brackets, put a closing and opening PHP tag, and anything between them.

?> Anything here // Content for registered users"; // To see the text, you need to log in

I think everything is clear here. Now let's look at the case when you need to hide part of a post, that is, part of the text of your article. Here I suggest using shortcodes. We will create a function with a shortcode and when writing an article you will simply enclose part of the text in this shortcode that will be hidden. There will also be a small bonus at the end that will make it easier for you to use this shortcode.

To create a shortcode, you need to open the file custom functions from your WordPress theme - function.php and add the code below to it. This should be done at the very end, before the PHP closing tag.

Function only_reg_info($atts,$content = null) ( if (is_user_logged_in() && !is_null($content) && !is_feed())( return $content; ) else ( return "";) ) add_shortcode("forreg", "only_reg_info");

In this function we use a similar condition as at the beginning of the article. In the fourth line in single brackets is the text that non-registered, non-authorized users will see. You can change it to something of your own or add code there, generally at your discretion.

In the sixth line we indicate the name of the shortcode - forreg. If you want, you can change it to your own, but then don’t forget to change it and other codes that will be indicated below in the article, so that everything continues to work, and you don’t write to me in anger that it’s NOT WORKING!!!.

Now, when writing an article, you simply include forreg in the shortcode required text who will hide.

//text that will be hidden for unauthorized visitors.

Small bonus

As I wrote above, I also want to add a small bonus that will make it a little easier for you to constantly use the shortcode. In order not to manually type this shortcode every time, I suggest adding a button to the editor, adding a button to the WordPress HTML text editor.

To do this, in the same function.php, after the function with the shortcode, add the following function:

Function add_new_quicktags() ( if (wp_script_is("quicktags")) : ?> if (QTags) ( QTags.addButton("forreg", "For registration.", "", "", "For registration.", "" , 1);