I want to add some custom menu points to the customize menu. So the user is able to edit the page much easier.
In your theme go to the function.php
and Code like this
function self_customizer_section($wp_customize) {
$wp_customize->add_section( 'section_name' , array(
'title' => __( 'Self Logo', 'my_theme' ),
'description' => 'theme general options',
));
/* LOGO */
$wp_customize->add_setting( 'self_logo', array(
'default' => get_template_directory_uri().'/images/mytheme.png'
));
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'self_logo', array(
'label' => __( 'Main Logo', 'my_theme' ),
'section' => 'section_name',
'settings' => 'self_logo',
)));
}
add_action('customize_register', 'self_customizer_section');
For more detail you can follow the below link he made the awesome tutorial on that question
See in continuation.
here is the link
Wordpress Theme Customization API Tutorial
Related
I am working on a wordpress theme and after theme installation, the default values set for customizer are not displayed on the page, but in customizers they appear. If I change something in a field in the customizer and click publish, it is displayed on the web page. Does anyone know why? the code doesn't seem to be a problem.
customizer.php:
<?php
function photonium_customizer_register($wp_customize){
$wp_customize->add_panel('home_panel', array(
'title' => 'Front Page',
'priority' => 1,
'capability' => 'edit_theme_options',
));
$wp_customize->add_section('home_section', array(
'title' => 'Home Section',
'description' => __('Here you can custom the Front Page content. <br/> To not display some fields, leave them empty.'),
'panel' => 'home_panel',
));
$wp_customize->add_setting('main_title', array(
'default' => __('Professional Photographer'),
));
$wp_customize->add_control('main_title', array(
'label' => 'Home Main Title',
'section' => 'home_section',
'priority' => 1,
));
$wp_customize->selective_refresh->add_partial('main_title', array(
'selector' => '.main-title',
));
}
add_action( 'customize_register', 'photonium_customizer_register' );
front-page.php:
<?php if( get_theme_mod( 'main_title') ): ?>
<p class="main-title"><?php echo get_theme_mod('main_title', 'Professional Photographer'); ?></p>
<?php endif; ?>
...
I am using penny auction wordpress theme, as i am new to wordpress. My question is to add more fields in side meta-box by using child theme, So for this I have successfully created and activated child theme, but I am stuck here to how can I add more text fields in meta box by using child theme functions file?
The easiest way to do that is to install the Meta Box plugin (https://wordpress.org/plugins/meta-box/), then add this to your child theme's functions.php file:
function yourprefix_register_meta_boxes( $meta_boxes ) {
$prefix = 'metaboxprefix_';
$meta_boxes[] = array(
'id' => 'samplefield',
'title' => __( 'Your Meta Box Title', 'yourtextdomain' ),
'post_types' => 'post',
'context' => 'normal',
'priority' => 'high',
'fields' => array(
array(
'name' => __( 'Your Text Field', 'yourtextdomain' ),
'id' => $prefix . 'yourfieldid',
'type' => 'text',
),
)
);
return $meta_boxes;
}
add_filter( 'rwmb_meta_boxes', 'yourprefix_register_meta_boxes' );
For future reference: http://metabox.io/
I wasn't sure where to post this question..
I recently discovered WordPress' "Theme Customizer" and am using it to make the pages easier to update for clients. Rather than the standard way of editing each individual page, clicking update, and then visiting the page to see the changes, I like how the Theme Customizer automatically previews your changes on the right side.
I am trying to get an understanding of how far I can go with the Theme Customizer before I go all out on this...
I've created a "Home Page" setting/section/control pictured here:
And here is the code for this:
function prowordpress_customize_register( $wp_customize ) {
// Settings, Sections, and Controls are defined here
// HOME PAGE
$wp_customize->add_setting( 'home_page_text' , array(
'default' => 'This is the home page text',
'type' => 'option',
'transport' => 'refresh',
));
$wp_customize->add_section( 'prowordpress_content_customizations' , array(
'title' => __('Home Page', 'prowordpress'),
'description' => __('Modify the Home Page', 'prowordpress'),
'priority' => 30,
));
$wp_customize->add_control( 'home_page_text_control', array(
'label' => __( 'Home Page Text', 'prowordpress' ),
'section' => 'prowordpress_content_customizations',
'settings' => 'home_page_text',
'type' => 'textarea',
));
$wp_customize->add_setting( 'home_page_template_select' , array(
'default' => 'test',
'type' => 'option',
'transport' => 'refresh',
));
$wp_customize->add_control(
new WP_Customize_Control(
$wp_customize,
'home_page_template_select',
array(
'label' => __( 'Home page template:', 'blankwptheme' ),
'section' => 'prowordpress_content_customizations',
'settings' => 'home_page_template_select',
'type' => 'select',
'choices' => array(
'template_one' => __( 'Template Layout 1' ),
'template_two' => __( 'Template Layout 2' )
)
)
)
);
}
add_action( 'customize_register', 'prowordpress_customize_register' );
You can see in the screenshot I've added a select menu for "Home page template"...
Is it possible I could set it up where the client can choose an existing "page template" from this select menu and then have the page preview/layout on the right hand side automatically inherit the page template settings and adjust the layout in real-time?
Again, I'm just trying to understand if this is feasible, and if anyone has tried something similar before. I realize this may require some AJAX or something along those lines.
Thanks for the help!
Yes, You can. I have done this type of layout selection in my own theme.
in your php file you need to do something like this -
<?php if ( get_option( 'home_page_template_select' ) === 'template_one' ) {
get_template_part( 'layouts/template-one' ); ?>
I hope that helps.
is there a way to add a new control to the "Menu" tab on the customize page?
picture to menu
I want a button right over "Menu Locations".
I've already try to use a add_control function like this:
$wp_customize->add_control( new WP_Customize_Control(
$wp_customize,
'test',
array(
'label' => __( 'Test', 'yespizza' ),
'section' => 'nav_menus',
'settings' => 'test_setting',
'priority' => 10,
)
));
I don't know how i can get the right section name for the menu.
regards
I want to know how to add a new submenu for a custom post type in creating a wordpress plugin.
What I have done for now, I've created a custom post type called 'funds'.
add_action( 'init', 'wnm_add_funds' );
function wnm_add_funds() {
register_post_type('wnm_funds',
array(
'labels' => array(
'name' => __( 'Funds' ),
'add_new' => __( 'Add New Fund' ),
'add_new_item' => __( 'Add New Fund' ),
'edit_item' => __( 'Edit Fund' )),
'public' => true,
'has_archive' => true,
'menu_position' => 100
)
);
}
This code adds a custom post type called 'Funds' and under it is two submenus ('funds','add new fund'). What I would like to do is to add new submenu under funds. Example I would like to add 'Fund Settings', so under funds there will be (funds,add new fund,fund settings).
how would i do that?
You can do this with:
http://codex.wordpress.org/Function_Reference/add_submenu_page
http://codex.wordpress.org/Roles_and_Capabilities
I don't know if the capability is set right for your cause, but this will work
<?php
add_submenu_page(
'edit.php?post_type=wnm_funds',
'Fund Settings', /*page title*/
'Settings', /*menu title*/
'manage_options', /*roles and capabiliyt needed*/
'wnm_fund_set',
'CALLBACK_FUNCTION_NAME' /*replace with your own function*/
);
To add settings/options to the page I recommend the settings API
A good (and bit long) tutorial how to use this: http://wp.tutsplus.com/tutorials/the-complete-guide-to-the-wordpress-settings-api-part-1/