I am developing a theme and I wanted to add some extra content to the built in background options page. I know how to use the settings API to create new theme options and settings but I can’t seem to figure out where it’s actually calling to the background page. I have searched through wp-includes/theme.php
and still not much there except to calls to the background functions and nothing that actually renders the page.
Could this not be done with an action?
The page content for custom backgrounds is created in
wp-admin/custom-background.php
. There is no action available where the fields are printed.To add new fields we have to print JavaScript into the page footer. The action is
'admin_footer-appearance_page_custom-background'
.To save those field values we have to hook into
'load-appearance_page_custom-background'
.The following example adds a new option for
background-origin
â useful if you have set a border aroundbody
in your stylesheet.I found the answer provided by @toscho very useful, but as I had more than one option to add, I have amended the code a little so that all I have to do is create a simple extended Class with a few options.
I also found it inconvenient to have the options simply added to the end of the list, so I’ve added a ‘position’ argument that allows you to select any of these options –
'first'
– Before the first setting (currently Position)'last'
– After the last setting (current Background Colour)Integer position
– The row number to insert the setting before (must be an integer)Here is the code –