[英]Wordpress logo upload option in theme panel
Hello every one i am facing one issue in adding logo option in my theme panel of wordpress i am using this code大家好,我在 wordpress 的主题面板中添加徽标选项时遇到一个问题,我正在使用此代码
function logo_display()
{
?>
<input type="file" name="logo" />
<?php echo get_option('logo'); ?>
<?php
}
function handle_logo_upload()
{
if(!empty($_FILES["demo-file"]["tmp_name"]))
{
$urls = wp_handle_upload($_FILES["logo"], array('test_form' => FALSE));
$temp = $urls["url"];
return $temp;
}
return $option;
}
function display_theme_panel_fields()
{
add_settings_section("section", "All Settings", null, "theme-options");
add_settings_field("logo", "Logo", "logo_display", "theme-options", "section");
register_setting("section", "logo", "handle_logo_upload");
}
add_action("admin_init", "display_theme_panel_fields");
The issue is its not saving logo and also not displaying it in admin as well.问题是它没有保存徽标,也没有在管理员中显示它。 I have tried this 10 times with different ways but this code is not working.我已经用不同的方式尝试了 10 次,但是这段代码不起作用。 Please look in this code and try it.请查看此代码并尝试一下。
You forgot to add else condition in your " handle_logo_upload " function.您忘记在“ handle_logo_upload ”函数中添加其他条件。 Try following code:尝试以下代码:
function logo_display()
{
?>
<input type="hidden" name="ologo" value="<?php echo get_option('logo'); ?>" readonly /><input type="file" name="logo" id="imgupload" style="display: none;" />
<a id="OpenImgUpload" class="button button-primary">Image Upload</a>
<?php echo get_option('logo'); ?>
<?php
}
function handle_logo_upload()
{
if(isset($_FILES["logo"]) && !empty($_FILES['logo']['name']))
{
$urls = wp_handle_upload($_FILES["logo"], array('test_form' => FALSE));
$temp = $urls["url"];
return $temp;
}
elseif(isset($_FILES["logo"]) && empty($_FILES['logo']['name'])){
$urls = $_POST["ologo"];
return $urls;
}
return $option;
}
function display_theme_panel_fields()
{
add_settings_section("section", "All Settings", null, "theme-options");
add_settings_field("logo", "Logo", "logo_display", "theme-options", "section");
register_setting("section", "logo", "handle_logo_upload");
}
add_action("admin_init", "display_theme_panel_fields");
You Should try this.你应该试试这个。 May this will help you.愿这对你有帮助。
https://kwight.ca/2012/12/02/adding-a-logo-uploader-to-your-wordpress-site-with-the-theme-customizer/ https://kwight.ca/2012/12/02/adding-a-logo-uploader-to-your-wordpress-site-with-the-theme-customizer/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.