[英]How can I make the user change any image on my wp theme just from the theme editor?
如何讓用戶僅從主題編輯器更改我的 wp 主題上的任何圖像?
例如:我的主題頁腳上有一個我硬編碼的背景圖像,我想讓用戶(管理員)能夠從主題編輯器中更改它,感謝高級
我不想使用這樣的東西:
<div class="footer-background background-image" style="background-image: url(<?php echo get_theme_file_uri( 'assets/images/bg.jpg' ) ?>)" >
如果你能給我一個關於這個的 wp 法典,那將會很有幫助,因為我在谷歌上找不到任何與我的問題相關的東西。
如果我是你,我會做以下事情
https://www.advancedcustomfields.com/resources/options-page/ https://www.advancedcustomfields.com/resources/image/
所以,你可以做這樣的事情(在functions.php中):
add_action( 'customize_register', function( $wp_customize ) {
$wp_customize->add_section(
'section_img',
array(
'title' => 'Images',
'priority' => 35,
)
);
$wp_customize->add_setting(
'footer_image'
);
$wp_customize->add_control(
new WP_Customize_Image_Control(
$wp_customize,
'footer_image',
array(
'label' => 'Footer image',
'section' => 'section_img',
'settings' => 'footer_image'
)
)
);
});
您可以通過以下方式獲得價值(在 footer.php 中):
get_theme_mod('footer_image');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.