Wordpress 获取模板 URL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3581353/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 18:37:41  来源:igfitidea点击:

Wordpress Get Template URL

wordpress

提问by Howard Zoopaloopa

I'm looking to return a template url rather than print it and bloginfo('template_url'); prints... anyone know of a version of this function I can use inside of a string I'm building to print at a laterpoint?

我希望返回一个模板 url 而不是打印它和 bloginfo('template_url'); 打印...有谁知道这个函数的一个版本,我可以在我正在构建的字符串中使用,以便稍后打印?

Example

例子

    $html = '<td style="width:40px;"><img src="';
    $html .= bloginfo('template_url'); // <-- messes up string because it prints.
    $html .= '/images/pause.png"></td>';
    return $html;

回答by Mikael Gr?n

I would recommend you use get_template_directory_uri()instead.

我建议你get_template_directory_uri()改用。

$html = '<td style="width:40px;"><img src="';
$html .= get_template_directory_uri();
$html .= '/images/pause.png"></td>';
return $html;

Read more about the method here: Function Reference/get template directory uri, Wordpress Codex

在此处阅读有关该方法的更多信息:函数参考/获取模板目录 uri,Wordpress Codex