简体   繁体   English

在wordpress中使用function.php

[英]Use of function.php in wordpress

what is the use of function.php in wordpress? wordpress中function.php的用途是什么?

   <?php 
function amazing_script_equeue(){wp_enqueue_style('customstyle',get_template_directory_uri().'/css/awsomew.css',array( ),'1.0.0','all');}
add_action('wp_enqueue_scripts','amazing_script_equeue');

what does the above code do when the page loads? 页面加载时,上面的代码做什么?

The codex puts it nicely: 法典很好地说明了这一点:

One way to change the default behaviors of WordPress is using a file named functions.php. 更改WordPress默认行为的一种方法是使用一个名为functions.php的文件。 It goes in your Theme's folder. 它放在主题的文件夹中。

The functions file behaves like a WordPress Plugin, adding features and functionality to a WordPress site. 功能文件的行为类似于WordPress插件,向WordPress网站添加了功能。 You can use it to call functions, both PHP and built-in WordPress, and to define your own functions. 您可以使用它来调用PHP和内置WordPress的函数,以及定义自己的函数。 You can produce the same results by adding code to a WordPress Plugin or through the WordPress Theme functions file. 您可以通过将代码添加到WordPress插件或通过WordPress主题函数文件来产生相同的结果。

The code in question is a function that is being called at runtime, which is pulling a file called /css/awsomew.css into the themes frontend. 有问题的代码是在运行时调用的函数,该函数/css/awsomew.css名为/css/awsomew.css的文件拉入主题前端。 This file is located at ...wp-content/your-theme-name/css/awsomew.css . 该文件位于...wp-content/your-theme-name/css/awsomew.css For more information on the wp_enqueue_style() function, see the codex as well. 有关更多信息, wp_enqueue_style()函数,看食品为好。

Theme functions.php behaves like a plugin that runs inside the theme file, almost all code you'll find on plugins will also run when added on functions.php file, 主题functions.php的行为类似于在主题文件中运行的插件,添加到functions.php文件中后,几乎所有在插件上找到的代码也将运行,

the above functions you have provided will add this stylesheet below inside your head tag, 您提供的上述功能会将此样式表添加到head标签的下方,

<link rel='stylesheet' id='customstyle' href='yoursite.com/wp-content/themes/themename/css/awsomew.css?ver=1.0.0' type='text/css' media='all' />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM