2016-12-29 31 views
0

我想将我的样式表链接到Wordpress中的另一个页面。实际的Wordpress安装位于实际站点内的文件夹内。它的成立这种方式,因为我只想使用WP为网站的特定部分(这是一种事后的想法,我知道这是不一定是“正确”的方式做事情...)在Wordpress中链接样式表

我有首页设置和样式都工作正常。但是,当创建一个新页面并尝试使用get_header来拉入样式时,它们不起作用。浏览器正在寻找名为styles.css的页面,而不是样式表。

我试着在functions.php文件中使用“enqueue”,但它仍然不起作用。我有我的样式表在主题文件夹中的副本,也有一个在CSS文件夹内。利用排队等待的CSS文件夹中的副本

例子:

wp_enqueue_script('styles', 'get_stylesheet_directory_uri()' . 'css/styles2.css'); 

*我在我的页面模板文件中使用get_header,(相同的头文件,其做工精细头版),它是链接是这样的:

<link rel="stylesheet" type="text/css" href="../css/styles2.css"> 

我敢肯定的问题是“../”,但是当我替补echo get_stylesheet_directory_uri().......代替../,它不因为它应该工作。

任何帮助将是伟大的,因为我更新WP开发。

谢谢大家

回答

0

你必须写这样的模板样式表的链接...

wp_enqueue_script('styles', get_template_directory_uri(). 'css/styles2.css', array(), '0.0.1'); 
0

添加样式表是这样的:

wp_enqueue_style('styles', bloginfo('template_url').'/css/styles2.css'); 

您可以查看详细here

0

你需要钩住css: 如果您使用的儿童主题则钩状:

add_action('wp_enqueue_scripts', 'enqueue_unique_function_name_here', 0); 
function enqueue_unique_function_name_here() 
{ 
    wp_enqueue_style('css_unique_handle_name_here', get_template_directory_uri(). 'folder_path_inside_child_theme/style_sheet_file_name_here.css', array(), '0.0.1'); 
} 

如果您正在使用父主题(无子主题),然后勾状:

add_action('wp_enqueue_scripts', 'enqueue_unique_function_name_here', 0); 
function enqueue_unique_function_name_here() 
{ 
    wp_enqueue_style('css_unique_handle_name_here', get_stylesheet_directory_uri(). 'folder_path_inside_child_theme/style_sheet_file_name_here.css', array(), '0.0.1'); 
} 

如果想在管理方面则只是改变排队钩子名称“wp_enqueue_scripts”为“admin_enqueue_scripts”。

立即尝试。

0

你用来代替wp_enqueue_style()用于排队风格
wp_enqueue_script

wp_enqueue_style用于排队脚本wp_enqueue_script()

wp_enqueue_style('styles', 'get_stylesheet_directory_uri()' . 'css/styles2.css'); 

这里是相同的完整的例子。

add_action('wp_enqueue_scripts', 'enqueue_custom_style'); 
function enqueue_custom_style() 
{ 
    wp_enqueue_style('styles', 'get_stylesheet_directory_uri()' . 'css/styles2.css'); 
}