How can WordPress add data to a website? Try the wp_head() function, Wordpress registration page plug-in

1 year ago (2023-12-02) Chief Editor
5 minutes
two hundred and eighty-three
zero

Sometimes, we will encounter a situation where our WordPress website theme template has been finalized, but we want to add some new functions to the WordPress website later. What should we do at this time? Continue to modify the WordPress website theme template? Of course, you can certainly modify the theme template. But after a long time, I may be unfamiliar with the current theme template, and it may be difficult to modify it. Is there any other way to add new features to the wordpress website? Of course there are. For some function applications, we can use the form of wp_head() function+plug-in to complete some functions. Let's take a look at how the wp_head() function converts the plug-in data into the foreground page.

1、 Create plug-ins for the wordpress website.

Enter the plugin directory/wp content/plugins/on the wordpress website, and create an app directory under the plugin directory, that is, create a plugin named app. As shown below:

Then, create two files in the app plug-in directory, a bbb.css file and an index.php file, as shown below:

The bbb.css file here is the style file of the plug-in, and index.php is the home page file of the app plug-in. The function we want to implement here is just a demonstration function, which is to modify the font size and color of the foreground page.

The index.php file code is as follows:

<? Php/* plugin name: app//This is required, otherwise the plugin uri cannot be found in the background plugin list: //wanlimm.comauthor: Non-stop version: 1.0description: This is a plug-in that uses the wp head() function */function my_head() {//Add a style file echo<link rel="stylesheet" href=". WP_PLUGIN_URL./app/bbb. css">;} if (! Is_admin()) {//If it is not the background, add the my_head function to the action hook wp_head hook of wordpress. add_action ("wp_head" ,"my_head");}

The code of the bbb.css file is as follows:

body{color:red; font-size:40px;}

Change the text color of the front page of the wordpress website to red, and the font size to 40 pixels.

2、 Enable plug-ins in the WordPress website background plug-in list.

After adding in the first step, we can see the app plug-in in the background plug-in list of the wordpress website, as shown below:

We click the "Enable" button to enable the app plug-in. Only when the plug-in is enabled will its functions be applied to the front page of the wordpress website. Of course, although we have enabled it now, the font of the frontend of our WordPress website is still unchanged. The following figure (the content we added last lesson).

3、 Add calling code in the WordPress website theme foreground.

Through the above two steps, we have prepared the function and are waiting for our WordPress website to call. At this time, we need to use the wp_head() header function, which is very powerful. It can add all the action functions we added to the wp_head hook of WordPress to the front page of the WordPress website. However, this wp_head() function must be added to the<head>tag on the front page of the wordpress website to be effective, as shown below:

At this time, let's take a look at the front page of the WordPress website to see if the page font has changed. At this time, the font becomes larger and red. As shown below:

The "Back to Home" beside it is blue because it is a link. If you want to change its color, you must set its color separately. Let's take a look at the source code again, as shown in the following figure, the wp_head() function inserts the style file bbb.css of the plug-in app we created into the<head>tag on the foreground of the wordpress website.

Of course, the wp_head() function will insert many other codes into the<head>tag at the same time as the plug-in bbb.css style file. Some codes are useless to us, and we can deal with them by some means. This will be introduced in our later articles.

All right, so far, this section is drawing to a close. The purpose of this lesson is to introduce“ How to add data code to the header of the front page of the wordpress website through the wp_head() function ”This function is widely used. Many wordpress plug-ins use the wp_head() function. If this function is not used, these plug-ins cannot be used.

These are my views. If you have different views, please comment. At the same time, welcome [like, share, collect] and [follow] me.

This article is written by: Chief Editor Published on Software Development of Little Turkey , please indicate the source for reprinting: //hongchengtech.cn/blog/1500.html
Kuke_WP editor
author

Related recommendations

1 year ago (2024-02-20)

What are the main contents of wms system in warehouse management

Original title: What does the wms system mainly embody in warehouse management? What does the wms system mainly embody in warehouse management? Warehouse management has standardized and intelligent process oriented management. A good warehouse management mechanism can improve the efficiency of warehouse managers, relieve their pressure, and complete efficient and accurate work. 1. Warehouse management is accompanied by the progress of the times
1 year ago (2024-02-18)

How to implement the mptt comment function of CMS content management system in Django?, Django management page

During the daily development of content related Web systems in the directory, whether it is Blog or CMS, if you need to add links to interact with users, you must need the comment function. Next, you can implement the comment reply function in Django based on Python's MPTT framework. Note: Because the user comment function will involve a
three hundred and ninety-four
zero
1 year ago (2024-02-18)

Best CMS content management system in 2022, good novel in 2021

Looking for the best CMS software to build your website? At a high level, CMS or content management systems can help you create functional websites without having to use code to build every page from scratch. However, different CMS software has different advantages and disadvantages, so you need to choose the tool that best suits your specific needs and budget. To help, we accept
four hundred and six
zero
1 year ago (2024-02-18)

Shenzhen promotes the access of 5G base station energy storage system to the virtual power plant management center in the city. Does the Shenzhen 5g government subsidize the flow package charge

Xinhua News Agency, Shenzhen, December 14 (Reporter Wang Feng) At the 2022 Carbon Peak Carbon Neutralization Forum and Shenzhen International Low Carbon City Forum held here in Shenzhen, Shenzhen Virtual Power Plant Management Center signed a cooperation agreement on virtual power plant construction with China Tower, China Telecom, China Mobile, China Unicom, Huawei Digital Energy and other units on the 13th, which will jointly promote the city's 5G base station energy storage system
three hundred and forty-three
zero
1 year ago (2024-02-18)

Common website cms content management system recommendation, common website cms content management software

CMS is the abbreviation of "Content Management System", which means "Content Management System" in Chinese. These systems have developed common website functions and provided them to users for download, greatly improving the efficiency of website construction. The most common functions of CMS are column management, article management, product management, picture management
three hundred and twenty-eight
zero

comment

0 people have participated in the review

Scan code to add WeChat

contact us

WeChat: Kuzhuti
Online consultation: