Dynamic URLs and how to use them in WordPress

Some website owners do not always prefer that the browser displays the same content of web pages to all visitors, and they want to change the content of the page based on variables related to the visitor, such as the type of device through which the site is visited, or the geographical location of the visitor, and this is exactly what dynamic links provide (Dynamic URLs). ).

In this article, we will highlight the concept of dynamic links and their benefits, then we will explain how to use them and benefit from them in WordPress based on one of the custom plugins.

The concept of dynamic links

Dynamic links, or what we can call Dynamic Smartlinks, can be defined as links to web pages whose content changes based on a variable related to the visitor browsing them, such as (his geographic location, time zone, IP address, or number The times he visits a web page with a dynamic link or other variables..).

That is, dynamic links are smart links that can be used to show personalized content to each user or group of users who visits the web page.

On the other hand, the other type of links in which the content of the displayed pages does not change depending on a variable is called Static URLs. Unlike dynamic links, they display the same content to all visitors regardless of their geographical location, the type of device they use to visit the page, or the number of times. Its visit or any other variable, i.e. any variables related to the visitor are not taken into account when the web page is displayed to him.

In fact, pages with static links exist on the server as a pre-generated file, while pages with dynamic links are generated based on inputs (values ​​of visitor variables). Web pages with static links include the entire content, and their content does not change unless modified. The HTML code of the page in a way, while web pages with dynamic links can be considered a template in which certain content fetched from databases is displayed, based on inputs that are usually information related to the visitor.

Dynamic links can usually be distinguished from static links by looking at the letters and symbols that make up the link. If you find a question mark (?) in the link, it is usually a dynamic link to a dynamic page, and if you do not find any question mark, then the link is a static link. For example, the following link is a dynamic link:

http://www.example.com/product.php?id=12345&sort=date

While the following link is a fixed link:

http://www.example.com/product.html

We say that a web page is dynamic if it was created using PHP, ASP, or one of the other server-side programming languages, while clarifying that the web page must be dynamic without its link containing a question mark, as we can follow a specific programming method in creating Dynamic links and changing page content based on variables without the need to make the page link include a question mark (this method is often followed with important and sensitive data that we do not want to display in the link).

Note: It should also be noted that any link in this format (http://www.example.com/product.php ? id=12345&sort=date) is not necessarily a link to a page whose content changes depending on variables related to the visitor. Texts may be used Written after the question mark for a purpose other than changing the content of the page.


Query string parameters in dynamic links

The part of the dynamic link located after the question mark (?) is called the query string . This is the part of the link that is used to display the relevant content to the visitor on the page. The query string consists of one or more variables or parameters, and each parameter has Value. The parameter name and value are separated by an equal sign (=), and operands are also separated using the symbol (&) or semicolons (;)

See the following dynamic link

https://example.com/page?car=mercedes&color=purpl

You will find that the query string is (car=mercedes&color=purple), and it consists of two parameters, the first of which is (car=mercedes) and the second of which is (color=purple), where (car) and (color) represent the names of the two parameters, and (mercedes) and (purple) represent ) are their values, and each pair (parameter name + parameter value) is separated by an equal sign (=). Note that the question mark (?) is not part of the query string, and the symbol (&) is not part of the parameters.

It is worth noting that query string parameters may usually be obtained from variables related to the user (such as the IP address), and they may also be the result of the user entering values ​​in the fields of a website page, or in other ways.

These transactions are of two types: passive or inactive link transactions, which do not change the content of the page and are used for tracking or other purposes. Active link transactions, which are used to change the content of the page in order to display more appropriate content to visitors based on the available information that is passed through the query string.


Benefits of dynamic links

In fact, it is preferable to avoid using dynamic links as much as possible for indexing reasons that we will highlight in the next paragraph, but despite this, using this type of links may be useful sometimes. For example, it may be useful to use dynamic links in the following cases:

  • Show promotions to specific people, such as people coming to the page from a specific site or source
  • Rearranging the content to ensure a better user experience based on the information that can be known about it
  • Offer premium content to visitors who reach your web page from email to reward them for signing up for your newsletter
  • Measuring the marketing benefit of one of your website pages using different marketing methods to determine the best method
  • Segments content by showing specific parts of it based on the value of one of the parameters in the query string
  • Dynamic smart links can also be useful in many other similar situations that require hiding or showing elements based on query strings

Note that the Google search engine takes advantage of dynamic links and query strings in performing search operations, so that when you perform a search using it, the phrase you enter in the search box will be placed as the value of a parameter in the search page link, and the relevant results will be shown.

When you enter another phrase in the search box and perform the search, the value of the parameter in the query string will change, and other search results will be displayed on the page different from the results that were visible, as is clear in the following image.

It should also be noted that other parameters may be added to the query string when searching on Google for many other purposes, and they may be added automatically by Google, or they may be in response to user interaction, for example when they filter search results to show pages in Arabic only.


Do search engines index dynamic links?

Since there is more than one copy of a page with a dynamic link, search engines have difficulty indexing it, which is why search engine crawlers do not favor dynamic links much, and prefer to index unique pages over pages of which there are multiple copies.

However, search engines can index pages with dynamic links that have one parameter well, but for pages with links that have more than one parameter, most search engines will not be able to index them well. 

That’s why both Google and Yahoo recommend using permalinks to pages you want to be indexed. When using dynamic links, it is preferable to keep the number of transactions small, and ensure that the values ​​of these transactions are short, so that this helps them crawl the page with the dynamic link.

The maximum number of parameters (and the number of digits of their values) of accessed dynamic pages that Googlebot, the crawler that Google uses to index web pages, can access is unknown.

But it is known that it is able to index pages that have a single parameter with a four-digit value. So be careful not to use more than one parameter, and make the parameter value four or fewer characters long in dynamic page links.


How to create dynamic links in WordPress

Taking advantage of all the benefits provided by dynamic links requires that you have a good knowledge of PHP or other similar languages ​​on the server side, but you can benefit to some extent from dynamic links and query strings in WordPress by using the Block Visibility plugin , which provides you with the ability to show or hide content. Based on the query strings in the link among many other hiding and showing options.

You will first install the Block Visibility plugin   by searching for the name of the plugin on the plugin installation page in the WordPress control panel, then clicking on the ( Install Now ) button, then waiting until the installation is complete, then clicking on the ( Activate ) button . If you do not know how to install a WordPress plugin, you can review our following article ( How to install a WordPress plugin and activate it on your site correctly ).

After installing and activating the plugin on your WordPress website, you will be able to use it to create dynamic links for your pages and articles, as the plugin settings will appear within the component properties when you select it in the component editor.

Create a new post by clicking the Add New Post button in your WordPress dashboard as shown in the following image (or go to the Edit Post or Pre-Existing Page using the Component Editor).

Add a title to the article, then insert two paragraphs, each as a separate component.

Select the component whose appearance you want to control according to the query string that will be presented within the dynamic link used to visit the page, then take a look at its options and you will notice that there is an additional set of options under a section called (Visibility).

These options were added by the Block Visibility add-on that you installed.

These options enable you to show or hide components on the page based on many variables without the need to use dynamic links and query strings, but you can also create dynamic links using them, as within the options there is a section for query strings, but it is usually not visible by default.

To show the section for creating dynamic links, click on the three dots next to the phrase ( Enabled Controls ), then put a check mark next to the ( Query String ) option by clicking on it.

Re-click on the three dots to hide the drop-down menu, then look under the Visibility options for the (Query String) section for creating the query string. This section will usually be at the bottom and will look like the following image.

  • You will find that the previous image has three text boxes, and you must enter one or more parameters in one of these boxes depending on how you want to hide and show the selected component:
    • If you want the component to appear when the link the page is accessed using includes at least one parameter from a group of parameters, you must enter one or more parameters in the first box (Required Queries (Any), and you must enter each parameter on a separate line in this The form is (p=v), where q represents the name of the parameter, and v represents its value. If one of the parameters in the query string of the link from which the visitor enters the page matches one of the parameters written in the first box, the component will appear for it.
    • However, if you want to show the component when the link includes a group of transactions together and not at least one transaction among the transactions, you must enter the transactions in the second box (“Required Queries (All)) in the same form as before (p=v), and in this case you must The link from which the visitor enters the page includes all the parameters that you enter in this box for the component to be displayed.
    • If you want to show the component in all cases except the case in which the link includes a specific parameter , then you must enter the parameters in the third box (Required Queries (Not). Then the component will be hidden when at least one of them is present in the link through which the page is accessed. Here also, each parameter is entered in the same manner as before (p=v).

The following image summarizes all previous cases.

Here we will continue explaining the implementation of the steps, but we will not explain the three cases and will only explain the first case, but you will be able to benefit from the other two cases in the same way if you take into account the differences between them as we explained previously. 

As you remember, we have inserted two paragraphs on the page we created, one (Hello, Egypt guys), and the other (Hello, Syrian guys), and we want to show the first paragraph when the link includes this parameter (ctry=eg), and the second paragraph when the link includes this Parameter (ctry=sy). To do this you must follow the following steps:

We select the first paragraph (Hello, guys from Egypt), then we enter within the first box in the Query String section the parameter whose presence in the link causes this paragraph to appear, which is the parameter (ctry=eg).

We also select the second paragraph (Hello, guys from Syria), then we enter in the first box in the Query String section the parameter whose presence in the link causes this paragraph to appear, that is, we enter the parameter (ctry=sy)

We now publish the article by clicking on the publish button , then we open its link and notice that both paragraphs did not appear. This makes sense because the link currently does not include any transactions.

Now we add to the page link in the previous image in the browser bar the question mark (?), followed by the parameter (ctry=sy), then we click on the (Enter) key on the keyboard to reload the page based on the modified link. We notice that the second paragraph has appeared. actually.

We now remove the parameter (ctry=sy) from the link, and put the parameter (ctry=eg) in its place, then click the (Enter) key, and we notice that the first paragraph has appeared, and the second paragraph that was visible has disappeared.

Note: If the link that the page is visited using contains the two parameters (ctry=eg) and (ctry=sy) at the same time, then the two paragraphs will not be shown. Rather, the paragraph whose parameter is closer to the end of the link (the right end of the link) will be shown. Because the name of the parameter in this case is the same for the first and second paragraph (ctry), but if the name of the parameter pertaining to the first paragraph is different from the parameter pertaining to the second paragraph, then the first and second paragraphs will be shown if the link contains both.

Conclusion

With this, we have finished explaining dynamic links, query strings, and transactions, and explaining how to use them in WordPress. As we noted in our article, actually benefiting from dynamic smart links requires knowledge of programming languages. If you want to use them for some purpose on your WordPress site and do not have the necessary technical skills, we We advise you to seek the help of a programmer who is an expert in the PHP language .

In conclusion, we would like to remind you again that using fixed links is better when it comes to indexing the page in search engines, so we advise you to stay away from dynamic links as much as possible and not use them unless the need arises.

Avatar photo
I am a young man who has been working in WordPress and e-marketing for 10 years. I would like to share my experience with you so that we can become professional in WordPress I will be happy to share the experience with you.