September 2019 - Build your online business

Friday, September 13, 2019

Search Engine Optimization (SEO) MODX Revolution
MODX is considered one of the most SEO-oriented CMS, consider a few simple steps that will help search engines to appreciate your site.

Configure robots.txt and .htaccess
The most important parameter for SEO, for more details on the robots.txt and .htaccess settings, see here - robots.txt and .htaccess in MODX Revo. By the way, at the time of development of the site - it is better to close it from indexing in robots.txt and open it only after everything is configured and filled.

Setting (SEF)
For more information about setting up the SEF links, see here - Setting up the CNC (SEF) in MODX Revolution.

404 error
Create a 404 page in the resource tree.


Then we specify the ID (the number in the resource tree of the control panel in brackets next to the page title) of our 404 pages in the system settings, for this, we go to the top menu of the admin panel "System Settings -> Site".





Unique meta tags: title, description, keywords
Meta tags are also an extremely important parameter for search engines, and you need to make them unique and reflect the theme of the page for each page.

There is a good component that creates additional fields for meta tags in the admin panel, with a check for the entry of keywords - SEO Pro. It also shows how the page will be displayed in the search engine (you can select the one you need in the component settings).






<base href="[[!++site_url]]">
<meta charset="[[++modx_charset]]">
<title>[[*longtitle:notags:default=`[[*pagetitle:notags]]`]] | [[++site_name]]</title>
<meta name="description" content="[[*description:notags:default=`[[++site_name]] | [[*longtitle:notags:default=`[[*pagetitle:notags]]`]]`]]">
<meta name="keywords" content="[[+seoPro.keywords:notags:default=`[[*pagetitle:notags]] [[++site_name]]`]]">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="canonical" href="[[~[[*id]]? &scheme=`full`]]">
<link rel="shortcut icon" href="/favicon.ico">
<link rel="stylesheet" href="/assets/tpl/css/style.css">


I also use the I / O modifier: default, this allows me to generate meta tags, if they were not filled out, from the required fields (in my case [[* pagetitle]] and [[++ site_name]]); more about modifiers see here - I / O filters (modifiers).

Setting sitemap.xml
After all the pages are full, you can create a sitemap for the search engines (sitemap.xml), see more about this here - How to create a sitemap.xml file in MODX Revo.

How to remove .html in url
Sometimes it is necessary to replace the .html extension with / (slash) at the url on the site (or delete .html altogether), for example, replace all links of the form "contacts.html" with "contacts /".

to do this, go to the top menu of the admin panel "Content -> Content Types", find "HTML" there and change it to / (or delete) its "File Extension".




Correctly specify links to resources
Very often, developers or content managers specify links to other resources through sef aliases, for example like this:
<a href="/kontakti.html"> go to the contacts section </a> however this is not true, because the resource alias (in this case, "kontakti") can be further changed, for example, to "contacts" and the link to contacts, accordingly, will stop working.

It is correct to specify links to other resources through the resource ID, i.e. regardless of the page alias - the page will open:
<a href="[[~10]] go to the contacts section </a>, where 10 is the ID of the contact page.

If you need a website for your business on MODX CMS , feel free to contact me


Getting fields of any resource in MODX Revo
Often when developing sites, you need to get the necessary fields of some resources, for example, display a phone in the header of the site, which the manager could change in the "Contacts" resource. So, let's look at how to do this with snippets.


fastfield
This snippet has more features than getResourceField, and it has convenient syntax.
You can download fastField from the official repository - https://modx.com/extras/package/fastfield
The syntax of the call looks like this:
[[# resourceID.field]]

Where  resourceID - ID of the desired resource, field - field name.

Examples of using the fastField plugin:

[[# 1.pagetitle]] - Output of the pagetitle resource with ID = 1;
[[# 1.tv.myTV]] - TV output with the name myTV for the resource with ID = 1;
[[# 1.properties.articles.articlesPerPage]] - Output of resource parameters with ID = 1;
[[# [[* * parent]]. introtext: default = `[[# [[* * parent]]. description]]`]] - Displays the annotation of the resource’s parent and if it is empty, it displays a description (fastField supports input filters - output);
[[# POST.name]] - the value of $ _POST ['name'] (and other global resources, similar to the getReqParam snippet)
Global arrays are supported: $ _GET, $ _POST, $ _REQUEST, $ _SERVER, $ _FILES, $ _COOKIE, $ _SESSION. The array type after sharp (#) is case sensitive. The element name of the array is also case sensitive. You can use the non-cacheable tag [[! # Get.name]] for cached resources.
Attention! Use the I / O filter: notags to prevent XSS attacks (for example: [[! # Get.name: notags]])




pdoField
The snippet is included in the pdoTools package, you can download it here - https://modstore.pro/packages/utilities/pdotools or in the official repository - https://modx.com/extras/package/pdotools

This snippet simultaneously has the capabilities of getResourceField and UltimateParent, that is, it displays any field of the specified resource or its parent, including TV parameters.

The difference from analogues is the work with documents of any contexts and the ability to specify additional parameters when fetching, which eliminates the need to display fields, for example, hidden resources. Also, by specifying the & class parameter, you can get the field of any MODX object. It can be called as an output filter.

A snippet can be called as an output filter:
[[* id: pdofield = `longtitle`]]

Or

[[pdoField?
& id = `[[* id]]`
& field = `longtitle`
& top = `2`
]]

PdoField also includes the fastField syntax:


[[# resourceID.field]]

See all the snippet parameters in the documentation here - https://docs.modx.pro/components/pdotools/snippets/pdofield




sitemap.xml in MODX Revo
For success SEO in your Landing Page and website, you need to create correct sitemap.xml
It is created to help search engines (Yandex, Google) index the pages of your site.

To create the sitemap.xml file, install the pdoSitemap snippet (add-on pdoTools), you can also use GoogleSiteMap, all settings are the same.

Resource setup for sitemap.xml
1. Create a sitemap resource and add the following to the “Document” and “Settings” tabs:

Document tab:

The title is sitemap.xml or sitemap, it doesn’t matter;
The template is empty;
Alias - sitemap;
Hide from the menu - Yes;
Published - Yes.



Settings Tab:

Content Type - XML;
Searchable - No;
Use HTML editor - No;
Freeze URI - Yes;
URI - sitemap.xml



2. In the content of our sitemap resource, call the desired snippet with the necessary parameters, if necessary:

[[! pdoSitemap]]
or
[[! GoogleSiteMap]]


3. Save our sitemap.xml resource

Check the result of work
To do this, enter in the address bar of the browser: http://www.mysite.ru/sitemap.xml

We indicate to search engines (on the example of Yandex and Google) a link to sitemap.xml
Yandex: In the webmaster’s dashboard, select "Indexing Settings" -> "Sitemaps" in the left menu. In the form that opens, enter the URL of the sitemap.xml file and click on the "Add" button.

Google: In the webmaster’s dashboard, select "Sitemaps" in the left menu. In the opened page, enter the URL of the sitemap.xml file and click on the "Submit" button.

You must also specify the Sitemap directive: http://site.ru/sitemap.xml in robots.txt

Original text  https://cat-art.ru/blog/sitemap-v-modx-revo