Wordpress 테마에서 이미지 URL을 가져오려면 어떻게 해야 합니까?
워드프레스에 대한 테마를 개발하고 있습니다.그리고 '이미지' 폴더에는 많은 이미지가 있습니다.하지만 브라우저에서 페이지를 가져가면 연결이 되지 않습니다.
내 코드는
index.displaces를 표시합니다.
<ul>
<li><a href="#"><img src="images/mindset.jpg" width="145" height="32" /></a></li>
워드프레스에서 이미지 경로를 얻는 기능이 있습니까?
src="<?php echo base_url()?>your_theme_dir/image_dir/img.ext"
뿐만 아니라.
src="<?php bloginfo('template_url'); ?>/image_dir/img.ext"
get_directory_uri();
이 함수는 테마 디렉토리 URI를 취득하는 데 도움이 되며, 아래 예시와 같이 이미지와 함께 사용할 수 있습니다.
<img src="<?php echo get_template_directory_uri(); ?>/images/mindset.jpg" />
저는 Stylesheet 디렉토리를 사용하여 작업을 수행해야 했습니다.
<img src="<?php echo get_stylesheet_directory_uri(); ?>/images/image.png">
를 사용해야 합니다.
<?php bloginfo('template_directory'); ?>
현재 WordPress 테마의 디렉터리를 반환합니다.
예를 들어 테마에 다음과 같은 이미지가 있는 경우example.jpg
폴더 이름 내부subfolder
의 폴더images
폴더입니다.
themes
|-> your theme
|-> images
|->subfolder
|-> examples.jpg
이렇게 접속합니다.
<img class="article-image" src="<?php bloginfo('template_directory'); ?> /images/subfolder/example.jpg" border="0" alt="">
src="<?php bloginfo('template_url'); ?>/image_dir/img.ext"
워드프레스 3.6을 위해 일했습니다. 나는 그것을 사용하여 헤더 로고를 얻습니다.
<img src="<?php bloginfo('template_url'); ?>/images/logo.jpg">
하위 테마를 개발하는 경우 다음을 사용할 수 있습니다.
<img src="<?php echo get_template_directory_uri(); ?>-child/images/example.png" />
get_directory_uri()는 URL을 현재 활성 테마(부모 테마)로 되돌리고 -child/를 추가한 후 이미지에 경로를 추가합니다(위의 예에서는 이미지가 다음 위치에 있다고 가정합니다).<child-theme-directory>/images/example.png
)
다음 사항을 강력히 권장합니다.
<img src="<?php echo get_stylesheet_directory_uri(); ?>/img-folder/your_image.jpg">
워드프레스 프로젝트에 추가하고 싶은 거의 모든 파일에 사용할 수 있습니다.이미지든 CSS든 상관없습니다.
img 폴더가 테마 폴더 내에 있는 경우 다음 예를 따르십시오.
<img src="<?php echo get_theme_file_uri(); ?>/img/yourimagename.jpg" class="story-img" alt="your alt text">
당신이 Function을 요청했지만 더 쉬운 방법도 있습니다.이미지를 업로드 할 때 창의 오른쪽 상단에 있는 URL을 복사하여src='[link you copied]'
비슷한 문제를 찾는 사람이 있다면 도움이 되길 바랍니다.
언급URL : https://stackoverflow.com/questions/3262925/how-can-i-get-the-image-url-in-a-wordpress-theme
'prosource' 카테고리의 다른 글
스프링 데이터(JPA)에서 파생된 쿼리에서 여러 속성을 기준으로 정렬하려면 어떻게 해야 합니까? (0) | 2023.03.19 |
---|---|
MongoDB: initAndListen 예외: 20 읽기 전용 디렉터리에 잠금 파일 생성 시도: /data/db, 종료 (0) | 2023.03.19 |
WordPress의 상대 URL (0) | 2023.03.19 |
공허한 약속을 angularjs로 작성하시겠습니까? (0) | 2023.03.14 |
Ajax를 사용하여 데이터 테이블에서 모든 행을 내보내려면 어떻게 해야 합니까? (0) | 2023.03.14 |