WordPress Backstage Upload Custom website logo

Source: Internet
Author: User

Requirements: Well knownGeneral website logo are fixed so I do the site is also used static logo file, but recently used WP to a customer to do the site, because the site now logo may need to redesign, socustomer put forward the need in the background can modify the website logo, receive the demand on the network to find how to solve, but found a lap did not find the desired effect (are how to modify the login logo wp), fortunately found two articles related to the article, Finally, according to the two articles themselves codeing finally realized the function code:1. Add the following code in the function
  
 
  1. <?php
  2. /**在function中添加以下代码
  3. * WordPress 添加额外选项字段到常规设置页面
  4. * http://www.wpdaxue.com/add-field-to-general-settings-page.html
  5. */
  6. $new_general_setting = new new_general_setting();
  7. class new_general_setting {
  8. function new_general_setting( ) {
  9. add_filter( ‘admin_init‘ , array( &$this , ‘register_logo‘ ) );
  10. }
  11. function register_logo(){
  12. //需要‘js/uploader.js组件
  13. wp _enqueue_script ( ' FLI-UPLOAD-JS ' $this -> url ' js/uploader.js ' Array ( ' jquery ' ' media-upload ' ' Thickbox ' ) );
  14. wp_enqueue_style( ‘thickbox‘ );
  15. wp_enqueue_style( ‘fli-upload-css‘, $this->url . ‘css/uploader.css‘ );
  16. Regi ster_setting ( ' General ' ' logo ' ' esc_attr '
  17. add _settings_field ( ' logo ' <label for= "logo" > " __ ' website logo ' ' </label> ' array (& $this Logo_fields_html ' ) ' General '
  18. }
  19. function logo_fields_html() {
  20. $value = get_option( ‘logo‘, ‘‘ );
  21. echo ‘<input type="text" class="regular-text ltr" id="logo" name="logo" maxlength="200" value="‘. $value .‘" readonly/> <input type="button" id="general_logo" class="button insert-media add_media" value="上传">‘;
  22. }
  23. }
  24. // 自定义后台Css和Js
  25. add_action( ‘admin_enqueue_scripts‘, ‘myAdminScripts‘ );
  26. function myAdminScripts() {
  27. Span class= "pun" >//topic load admin js
  28. wp _register_script ( ' default ' Span class= "pun", Get_template_directory_uri () '/admin.js ' array (), " , ' all '
  29. wp_enqueue_script( ‘default‘ );
  30. wp _register_style ( ' default ' Span class= "pun", Get_template_directory_uri () '/admin.css ' Array (), " ' all ' );
  31. wp_enqueue_style( ‘default‘ );
  32. }
  33. ?>
2. Add code to the theme Admin.js
  
 
  1. options_general();
  2. //在常规选项页面添加自定义信息
  3. function options_general () {
  4. if(!Islocatl_pathname(‘options-general.php‘))return;
  5. Open the Upload window when you click the upload button or INPUT element
  6. jQuery(‘#general_logo,#logo‘).click(function() {
  7. //打开上传窗口需要js/uploader.js组件
  8. tb_show(‘‘, ‘media-upload.php?type=image&TB_iframe=true‘);
  9. return false;
  10. });
  11. //图片上传页面回传
  12. //html:为选择的图片元素
  13. window.send_to_editor = function(html) {
  14. imgurl = jQuery(html).attr(‘src‘);
  15. // 保存值并写入optuions表
  16. jQuery(‘#logo‘).val(imgurl);
  17. //删除图片上传窗口
  18. tb_remove();
  19. return false;
  20. } //end send_to_editor
  21. }
  22. //当前页面是否是指定的页面
  23. function Islocatl_pathname (pathname) {
  24. return location.pathname.indexOf(pathname)>=0;
  25. }//end 当前页面是否是指定的页面


Reference:Advanced Tutorials (34): Call the new Media Center to upload images
Customize and use WordPress image upload function
WordPress add extra option field to General Settings page


From for notes (Wiz)

WordPress Backstage Upload Custom website logo

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.