plugins - Image path in childs theme

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 plugi

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
Add a comment  | 

1 Answer 1

Reset to default 0

Use 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742296632a4417255.html

相关推荐

  • plugins - Image path in childs theme

    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 plugi

    17小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信