在wordpress中使用function.php


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');

当页面加载时,上面的代码会做什么?

编码很好地表达了这一点:

改变WordPress默认行为的一种方法是使用一个文件命名为functions.php。它位于主题的文件夹中。

函数文件的行为类似于WordPress插件,添加了一些功能以及WordPress网站的功能。你可以用它打电话函数,包括PHP和内置WordPress,并定义自己的功能。通过将代码添加到WordPress插件或通过WordPress主题功能文件。

有问题的代码是一个在运行时调用的函数,它将一个名为/css/awsomew.css的文件拉入主题前端。此文件位于...wp-content/your-theme-name/css/awsomew.css。有关wp_enqueue_style()函数的更多信息,请参阅代码集。

Theme functions.php的行为就像一个在主题文件中运行的插件,当添加到functions.php文件中时,你在插件上找到的几乎所有代码都会运行

您提供的上述函数将在下面的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' />