Cómo puedo obtener la ruta de la imagen en wordpress


Estoy desarrollando un tema para wordpress.Y tengo muchas imágenes en la carpeta "imágenes".Pero cuando tomo la página en el navegador no viene

Mi código es

Index.php

<ul>
<li><a href="#"><img src="images/mindset.jpg" width="145" height="32" /></a></li>

¿Hay alguna función para obtener la ruta de la imagen en wordpress ?

Author: Linto P D, 2010-07-16

7 answers

src="<?php echo base_url()?>your_theme_dir/image_dir/img.ext"

También

src="<?php bloginfo('template_url'); ?>/image_dir/img.ext"
 45
Author: Sadat,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-07-16 07:58:37

También puede definir la ruta de la imagen de la siguiente manera

<li><a href="#"><img src="/wp-content/theme-name/images/mindset.jpg" width="145" height="32" /></a></li>
 3
Author: Owais Alam,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-10-29 12:19:04

Necesitas usar

 <?php bloginfo('template_directory'); ?>

Devuelve el directorio del tema de WordPress actual.

Ahora, por ejemplo, si su tema tiene alguna imagen llamada example.jpg dentro de alguna carpeta nombre subfolder en la carpeta images.

 themes
   |-> your theme
          |-> images
                |->subfolder
                      |-> examples.jpg

Se accede así

 <img class="article-image" src="<?php bloginfo('template_directory'); ?> /images/subfolder/example.jpg" border="0" alt="">
 3
Author: Hitesh Sahu,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-04-22 08:20:47

src="<?php bloginfo('template_url'); ?>/image_dir/img.ext"
funcionó para mí para wordpress 3.6 lo utilicé para obtener el logotipo de encabezado usando como

<img src="<?php bloginfo('template_url'); ?>/images/logo.jpg">
 2
Author: Bikram Shrestha,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-08-16 06:16:02

Get_template_directory_uri();

Esta función le ayudará a recuperar el URI del directorio del tema, y se puede utilizar con sus imágenes, su ejemplo a continuación:

<ul>
    <li>
        <a href="#">
            <img src="<?php echo get_template_directory_uri(); ?>/images/mindset.jpg" width="145" height="32" />
        </a>
    </li>
</ul>
 2
Author: Allen,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-11-06 13:30:10

Usted pidió Función pero hay una manera más fácil también. Cuando subas la imagen, copia su URL que está en la parte superior derecha de la ventana (Ver captura de pantalla) y pégala en el src='[link you copied]'. Espero que esto ayude si alguien está buscando un problema similar.

 0
Author: Javapocalypse,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-07-26 21:08:17

Tuve que usar el directorio Stylesheet para trabajar para mí.

<img src="<?php echo get_stylesheet_directory_uri(); ?>/images/image.png">
 0
Author: Ian,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-07-12 05:11:46