简体   繁体   中英

How to make theme elements customizable in wordpress?

In Wordpress there's a menu option called 'Appeareances'. I want to add (eg) a submenu 'header' there and then be able to customize the header from within wordpress (administration page).

From what I understood I have to have a 'functions.php' file in my theme folder. In the 'functions.php' file I write something like this:

<?php add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function); ?>

Of course with adapted arguments (which I'm not entirely sure what those should be since I feel quite lost in all this).

CODEX is your best friend ..

And like the codex say, if you want to add an entry to the 'Appearance' menu , use

For Appearance: add_submenu_page( 'themes.php', ... );

or adapted to your case :

add_submenu_page( 'themes.php', 'Header', 'Header', 'edit_theme_options', 'customize_header','my_callback');

But ..:

Also see
> add_theme_page()

like so :

 add_theme_page( $page_title, $menu_title, $capability, $menu_slug, $function );

Quoting from codex :

Parameters

$page_title (string) (required) The text to be displayed in the title tags of the page when the menu is selected

  Default: None 

$menu_title (string) (required) The text to be used for the menu

  Default: None 

$capability (string) (required) The capability required for this menu to be displayed to the user.

  Default: None 

$menu_slug (string) (required) The slug name to refer to this menu by (should be unique for this menu).

  Default: None 

$function (callback) (optional) The function to be called to output the content for this page.

TL;DR version

All the above said in general for custom menu entries, but in the specific case of custom header, all you actually need to use is :

add_theme_support( 'custom-header' );

See details here : http://codex.wordpress.org/Custom_Headers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM