无法在wordpress中使用我自己的主题链接样式表和图像


Unable to link stylesheet and images in wordpress using my own themes

我已经上传了自己的设计。我只是不能得到正确的样式表链接。目前我的主题驻留在wp-content-themes-(carrental->我的主题文件夹名称)-style.css中。我的index.php页面也和style.css.

在同一个文件夹中。

我是这样链接的:

// for the style.css
<link rel="stylesheet" href="<?php bloginfo('style.css'); ?>" type="text/css"  />
// for image in index.php
<img src="<?php bloginfo('carrental'); ?>/assets/acr-logo-1.jpg" width="200" height="100">

请问正确的链接方式是什么?

包含样式表和脚本文件的最佳方法是在functions.php中通过wp_enqueue_script()和wp_enqueue_style()。以wordpress上默认激活的主题为例(例如214)。

例如,使用wp_enqueue_script,将确保脚本文件加载一次,无论如何,所以没有不愉快的意外。以jquery为例,你可以把它添加为其他脚本的依赖项。

如果你想包含在index.php的头文件中,你可以使用更多的选项:- ">,另一种选择是使用…src = "回声get_stylesheet_uri () . .或者您可以使用其他函数返回您的主题路径,就像其他人已经在这里写的那样。

这个想法是输出函数返回,所以get_stylesheet_uri()不起作用,因为您没有回显它。当您希望将值存储在变量中时,可以使用get_stylesheet_uri()。

但首选的方式仍然是使用wp_enqueue_script和wp_enqueue_style函数

下面的代码将返回样式表路径

bloginfo('stylesheet_url');

所以使用:

<link rel="stylesheet" type="text/css" href="<?php echo bloginfo('stylesheet_url'); ?>">

回显样式表链接!

关于bloginfo的更多信息可以在这里找到

对于样式表,必须使用样式

的link元素
bloginfo('stylesheet_url');

对于图像,必须给出图像的完整url比如如果你的图片目录在你的主题中那么在图片源中你可以输入这个

bloginfo('stylesheet_directory').'/images/imagname.png'

不要使用绝对url..使用完整的url。参见下面的代码

<link href="<?php echo get_template_directory_uri().'/style.css" />
<img src="<?php echo get_template_directory_uri().'/assets/acr-logo-1.jpg' ?>" />