Hook Prioritization in GeneratePress Explained: Controlling the Order of Elements

in using GeneratePress Theme construction WordPress At the time of the website, the Block Element and Hook The system provides powerful page insertion capabilities. Many users will insert customized modules, such as prompt boxes, advertisements, author information, etc., under the title of the article, at the end of the content or in the sidebar. The display order of these modules depends on the "Hook Priority".

In this article, we will illustrate how Hook Priority works and how to set it up by way of a practical demonstration.

Image [1] - How to Control the Display Order of Page Elements Using Hook Prioritization in GeneratePress

i. The default priority is 10

When you create a Block ElementThe system defaults to 10 if no priority is set when a Hook is inserted into a page.

For example. generate_after_header In these two Hooks, content blocks are added:

  • The first is the blue background container (default priority 10)
Image [2] - How to Control the Display Order of Page Elements Using Hook Prioritization in GeneratePress
  • The second is the pink background container (also default priority 10)
Image [3] - How to Control the Display Order of Page Elements Using Hook Prioritization in GeneratePress

Because the priority is the same, the system displays them in the order they were created. That is, the blue container created first comes first and the pink container comes second.

Image [4] - How to Control the Display Order of Page Elements Using Hook Prioritization in GeneratePress

II. Changing the display order by modifying the priority

You can manually set the priority value to control the order of the elements:

  • Set the priority of the blue container to 12
Image [5] - How to Control the Display Order of Page Elements in GeneratePress Using Hook Prioritization
  • The pink container stays at the default 10

After refreshing the page, the blue container will be displayed after the pink container.

Image [6] - How to Control the Display Order of Page Elements in GeneratePress Using Hook Prioritization

The conclusion is that the smaller the value the higher the priority, the further forward the element is. The larger the value the higher the priority, the further back the element goes.

III. Inserting subheadings between article titles and meta-information

This is a very common scenario: one wishes to insert a subheading or descriptive content to be displayed in the articlecaptionand between meta-information such as release date.

Default:

  • The title of the article uses the H1 tab (of a window) (computing)
  • Meta-information (e.g., author, date) is also passed through the Hook Insert, priority 10
  • If you create a subtitle block that also uses the generate_after_entry_titleIf the priority is 10, then it comes after the meta-message
Image [7] - How to Control the Display Order of Page Elements Using Hook Prioritization in GeneratePress

Solution:

  • Set subheading priority to 7 (less than 10)
Image [8] - How to Control the Display Order of Page Elements Using Hook Prioritization in GeneratePress
  • This way the subtitle is displayed between the title and the meta information
Image [9] - How to Control the Display Order of Page Elements in GeneratePress Using Hook Prioritization

If you set the priority to 11, the subtitle appears after the meta information.

Image [10] - How to Control the Display Order of Page Elements in GeneratePress Using Hook Prioritization
Image [11] - How to Control the Display Order of Page Elements Using Hook Prioritization in GeneratePress

IV. Controlling the order in which content blocks are displayed at the end of an article

Many sites will add modules at the end of articles such as:

  • Author Information
  • Related Articles
  • advertisements or CTA blocs
Image [12] - How to Control the Display Order of Page Elements Using Hook Prioritization in GeneratePress

These modules are usually inserted in the generate_after_entry_content in this Hook, and the footer meta information (Footer Meta) also uses this Hook with priority 10.

Image [13] - How to Control the Display Order of Page Elements Using Hook Prioritization in GeneratePress

If you want the custom module to appear above the footer meta:

  • Set the priority of this module to 9
Image [14] - How to Control the Display Order of Page Elements Using Hook Prioritization in GeneratePress

This allows you to adjust their top and bottom order without changing the HTML Structure or writing CSSThe

Image [15] - How to Control the Display Order of Page Elements Using Hook Prioritization in GeneratePress

summarize

Hook priority is GeneratePress One of the important mechanisms for controlling the structure of a page:

  • The default priority is 10
  • The smaller the priority value, the more content is displayed first
  • If multiple elements use the same Hook and have the same priority, they are listed in the order they were created.
  • Flexibility to insert advertisements, subheadings, explanatory text, etc. without code modifications

Proficiency in the way Hook and Priority are combined helps to better customize the page content layout and achieve a well-structured presentation.

Recent Updates


Contact Us
Can't read the tutorial? Contact us for a free answer! Free help for personal, small business sites!
Customer Service
Customer Service
Tel: 020-2206-9892
QQ咨詢:1025174874
(iii) E-mail: info@361sale.com
Working hours: Monday to Friday, 9:30-18:30, holidays off
? Reprint statement
This article was written by: thieves will be rats and mice courage
THE END
If you like it, support it.
kudos2373 share (joys, benefits, privileges etc) with others
commentaries sofa-buying

Please log in to post a comment

    No comments