WordPress knowledge sharing

Detailed Graphic and Text Tutorial on the Use of GeneratePress Theme Hooks

GeneratePress topic hooks It is a more useful function. Lao Wei's understanding is similar to Code Snippets plug-in Function, but more powerful. Code Snippets can only add various php codes, while Hook can also add statistics codes, js codes, etc. Even non professional developers can make various changes to the theme after they are familiar with Hook. In this article, Lao Wei teaches you how to use GeneratePress Theme Hooks function.

Two core 4G memory and 3M bandwidth are selected for the theme and plug-in of foreign website construction, which can run smoothly.
Domestic servers: Alibaba Cloud Tencent Cloud (All have vouchers, which can be used to save money when paying), I don't know how to select regions and configurations. Please add Lao Wei's contact information on the right side of the page. Let's study it together.

Foreign trade websites, B2C/C2C, etc. suggest registering domain names abroad. open Namesilo official website , enter the domain name to be registered in the search box, select it and then register. Remember to use the discount code to save money before paying. Discount code click Course of domain name registration of foreign domain name provider Namesilo obtain.

Suggested choice of foreign trade website Hostinger virtual host , the price is cheap and the performance price ratio is very high! Hostinger topic
SiteGround virtual host Moderate price, good service! SiteGround Theme

GP Premium Enable Hook

Hooks is an advanced function of GeneratePress theme Installing the GP Premium plug-in Before use.

For those who are not familiar with the advanced plug-in of GeneratePress, please see Detailed Graphic Tutorial of GP Premium Plug in Installation and Deployment

Next, on the right side of Wordpress Background>Appearance>generatepress, Activate to enable Elements, as shown in the following figure.

After enabling, you can see the buttons of elements (red arrows) on the left and top of the page.

 GP Premium Enable Elements

GP Premium Enable Elements

Create a new hook and set it

1. New hook

Then click Elements to start creating a hook.

Go to the top of the page and click add new element. In the pop-up window, select the element type as hook, and click create to create.

 GP Premium New Hook

GP Premium New Hook

2. Set hook

The created hook is a page similar to the post publishing page. If you have used it Code Snippets plug-in and Header Footer Code Manager Plug in You should be familiar with this interface. Generally, the operations are similar.

It doesn't matter if you are a novice or Xiaobai has not been exposed to such a complex operation interface. Old Wei will explain it to you in the simplest and straightforward language.

As shown in the figure below, Lao Wei divided the operation interface into four parts.

Part I It is the area where the code is placed.

You can see that the code area includes two parts. One is to give the hook a name. The following lines 1, 2, 3 are the code area. For example, in the figure below, Lao Wei puts the website statistics code.

Part II Is the settings.

Let's separate the explanation line by line.

  • After the hook, click the drop-down arrow to see many options, such as header, navigation, comments, content, footer, etc. These indicate that the hook needs Where to insert into the current page (These are all components of wordpress. If you are unfamiliar with them, please Understand the basic structure and layout of WordPress web pages

Taking the website statistics code in this example as an example, Lao Wei chose wp_footer (shown below). If you want to further select the location of the footer, you can select before_footer or after_footer in the drop-down box.

You can Diagram of hook location of GeneratePress To figure out where you want to insert yourself.

  • Fill in the short code in the content and check Execute Shortcodes;
  • Fill in the PHP code in the content and check Execute PHP;
  • Priority means priority. When a hook conflicts with a plug-in or code, priority is used to adjust the order of execution;
 GP Premium setting hook

GP Premium setting hook

Part III It is the display rules area of hook.

It means which pages can execute this code and which users can show it to. It is displayed to all users on all pages by default. Most of the time, we want to display it on a specific page. You can change the settings by following the rules below.

  • Location is the display code of the whole site by default. According to personal needs, it can be displayed on the article page, or only on the blog page, or only under a certain category directory;
  • Exclude means to exclude certain pages. The contents after pull-down are the same as those of Location, The meaning is just the opposite: don't show it on these pages;
  • Users: the meaning of the display to which users. It can be given to all users, logged in users, logged out users, and users of different levels;
 GP Premium setting hook display rules

GP Premium setting hook display rules

Part IV It is an internal Notes area.

It is used to add comments to this hook, to help you remember why you added this hook and what it is used for.

Publish hook

After the above settings are completed, click Update Release on the right side of the page, and the code will take effect immediately. You can change these options at any time when there are changes later, which is very convenient.

Hook cannot execute PHP code

After checking Execute PHP, the page prompts "Unable to execute PHP as DISALLOW_FILE_EDIT is defined", which means that PHP code cannot be executed. The solution is as follows:

Open the wp-config.php file in the root directory of the WordPress website, find the definition ('DISALLOW_FILE_EDIT ', false);, and delete it.

After the page is refreshed, there is no error prompt.

Lao Wei's comments

GeneratePress Theme Hooks It is especially useful for our theme design process and when we have customization requirements in the later stage. It can help us realize various ideas and functions without adding plug-ins. The hook function needs to be GP Premium Plug in Elements can only be used after it is opened in. It is one of the many functions of elements. Later, Lao Wei will also write examples of hook to explain how to use it.

Like( one )
Article name: Detailed Graphic and Text Tutorial on the Use of GeneratePress Theme Hooks
Article link: https://www.vpsss.net/23767.html
Copyright notice: The resources of this website are only for personal learning and exchange, and are not allowed to be reproduced and used for commercial purposes, otherwise, legal issues will be borne by yourself.
The copyright of the pictures belongs to their respective creators, and the picture watermark is for the purpose of preventing unscrupulous people from stealing the fruits of labor.