admin管理员组文章数量:1332383
I hope you can help me. How do I have to change the file path to get an specific image from my upload folder in my plugin/shortcode? I have added the following lines to my childs theme - functions.php but it doesn't work.
add_shortcode( 'webcamtime', 'webcamtime_timestamp' );
function webcamtime_init (){
function webcamtime_timestamp() {
$file = '/wp-content/uploads/webcam/webcamimage.jpg';
$filename = basename($file);
if (file_exists($filename)) {
return "Last modified: " . date ("F d Y H:i:s.", filemtime($filename));
}
}
}
add_action('init', 'webcamtime_init');
Thank you in advance!!
I hope you can help me. How do I have to change the file path to get an specific image from my upload folder in my plugin/shortcode? I have added the following lines to my childs theme - functions.php but it doesn't work.
add_shortcode( 'webcamtime', 'webcamtime_timestamp' );
function webcamtime_init (){
function webcamtime_timestamp() {
$file = '/wp-content/uploads/webcam/webcamimage.jpg';
$filename = basename($file);
if (file_exists($filename)) {
return "Last modified: " . date ("F d Y H:i:s.", filemtime($filename));
}
}
}
add_action('init', 'webcamtime_init');
Thank you in advance!!
Share Improve this question asked Jul 2, 2020 at 23:18 user190998user190998 2- 1 why don't you put the image within your child-theme folder? – Sabbir Hasan Commented Jul 2, 2020 at 23:51
- Please specify what "it doesn't work" means. Also, the basename function only gives you the last bit (filename) of the full path to your file. It's no surprise that the file_exists function using that, will return false. You'll have to specify the full path to the file for that to work. – Coen Jacobs Commented Jul 5, 2020 at 6:52
1 Answer
Reset to default 0Use the ABSPATH
constant defined in the wp-config.php
:
$filename = ABSPATH . 'wp-content/uploads/webcam/webcamimage.jpg';
You don't have to use basename()
function since it would return only the last component from the full file path, i.e. webcamimage.jpg
, and it isn't what you want to use with filemtime()
function.
本文标签: pluginsImage path in childs theme
版权声明:本文标题:plugins - Image path in childs theme 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742296632a2448863.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论