How can I change an image using WordPress customize ($wp_customize)? - php

I have the following code below, but I can't figure out why it's not working. All I get from my template is a blank screen. Any ideas? I'm using the latest version of WordPress.
function twentyone_customizer_register($wp_customize)
{
$wp_customize->add_section('logo_changer', array(
'title' => __('Images', 'twentyone'),
'description' => 'Change index page background image.'
));
$wp_customize->add_setting('logo_image', array(
'default' => 'http://localhost/twentyone/wp-content/themes/twentyone/assets/img/showcase.jpg'
));
$wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, 'logo_image', array(
'label' => __('Edit Showcase Image', 'twentyone'),
'section' => 'logo_changer',
'settings' => 'logo_image'
)));
}
add_action('customize_register', 'twentyone_customizer_register');

I've solved my problem and I have edited the code to reflect the changes. I named the function starting with a number and that caused the theme customizer not to work.

Related

Wordpress + Divi: Custom Section Toggle

I have a child theme editing the main-structure-elements.php file from the Divi parent theme. I have tried to override this file by moving it into the child theme and making the changes there, as well as modifying the functions.php file to require that file, still no luck.
I just need to add a toggle to the Divi sections that adds a css filter. This is the code I have written in the main-structure-elements.php file which works great in the main divi file but is unrecognized if added just in the child theme file.
public function get_fields() {
$fields = array(
'fullpage_height' => array(
'label' => esc_html__( 'Enable Fullpage', 'et_builder' ),
'type' => 'yes_no_button',
'option_category' => 'configuration',
'options' => array(
'off' => et_builder_i18n( 'No' ),
'on' => et_builder_i18n( 'Yes' ),
),
'default' => 'off',
'description' => esc_html__( 'Here you can select whether or not your page should have Full Height enabled. This must be enabled on all sections to function', 'et_builder' ),
'tab_slug' => 'advanced',
'toggle_slug' => 'layout',
'default_on_front' => 'off',
),
this code then is triggering this code later in that same file.
if ( 'on' === $fullpage_height ) {
$this->add_classname( 'fullpage-vertical' );
}
I have been working on this for days, any insight would be a life saver
Did you try run this code as snippet using plugin "Code Snippets"? Maybe at this way the code will work fine.

Wordpress - create customizer objects from wpdb response

So I have the following code:
add_action('customize_register', 'homepage_sections');
//products
function homepage_sections($wp_customize){
$wp_customize->add_panel('homepage_sections', array(
'title' => 'Homepage Sections',
'priority' => '20'
));
$wp_customize->add_section('homepage_settings_section', array(
'title' => 'Homepage settings',
'panel' => 'homepage_sections',
));
$wp_customize->add_setting('homepage_settings_setting', array(
'default' => 1
));
$wp_customize->add_control('homepage_settings_control', array(
'section' => 'homepage_settings_section',
'settings' => 'homepage_settings_setting',
'label' => 'Number of sections',
'description' => 'Number of sections in homepage',
'type' => 'number'
));
global $wpdb;
$sections=$wpdb->get_results('SELECT section_id, section_title FROM vt_homepage_sections;');
foreach($sections as $key){
$section_id=$key->section_id;
$cust_setting_id=$section_id.'_setting';
$cust_control_id=$section_id.'_control';
$wp_customize->add_setting($cust_setting_id,array(
));
$wp_customize->add_control($cust_control_id,array(
'settings' => $cust_setting_id,
'section' => 'homepage_settings_section',
'label' => 'test Control'
));
}
}
Issue
Everything works fine when i don't use variables which contain a value fetched using $wpdb. Is $wpdb object loaded after customizer framework?
When I use the code above, the above customized objects font appear in the customizer panel. Would appreciate hints to what's wrong with my code above.
Thanks in advance,
J
Please try this like this '$sections = $wpdb->get_results('SELECT section_id, section_title FROM vt_homepage_sections');'
define global class at the start of function and check.

wordpress Call to a member function add_section() on a non-object in functions.php line 5

Hey I'm kinda new to php and wordpress development and I'm just experimenting with how wordpress works and how the themes work. Now I have tried looking this up many times but no help. It was always something different and things that worked for those people, didnt work for me. here is the code,
<?php
function sandor_hero_cap() {
$wp_customize->add_section('sandor_subhead_title', array(
'title' => __('Sub-Header', 'sandor'),
));
$wp_customize->add_setting('sandor_subhead_title', array(
'default' => 'A Virtual PLAYGROUND',
'capability' => 'edit_theme_options',
'sanitize_callback' => 'sanitize_text_field'
));
$wp_customize->add_control('sandor_subhead_title', array(
'label' => __('Sub-Header Title', 'sandor'),
'section' => 'sandor_subhead_section',
'priority' => 5,
'settings' => 'sandor_subhead_title'
));
}
add_action( 'customize_register', 'sandor_hero_cap' );
?>
the error that im getting is:
Call to a member function add_section() on a non-object in functions.php line 5
I have tried a lot of things but nothing seems to be working, hopefully you guys can help me solve this issue. thanks :)
You're missing the $wp_customize argument. And, if I'm not mistaken, it might be an idea to use a different name for add_setting and add_control. See the code below.
function sandor_hero_cap($wp_customize) {
$wp_customize->add_section('sandor_subhead_title', array(
'title' => __('Sub-Header', 'sandor'),
));
$wp_customize->add_setting('sandor_playground', array(
'default' => 'A Virtual PLAYGROUND',
'capability' => 'edit_theme_options',
'sanitize_callback' => 'sanitize_text_field'
));
$wp_customize->add_control('sandor_playground', array(
'label' => __('Sub-Header Title', 'sandor'),
'section' => 'sandor_subhead_section',
'priority' => 5,
'settings' => 'sandor_subhead_title'
));
}
add_action( 'customize_register', 'sandor_hero_cap' );

wordpress custom_header does not save any changes

i'm building a wp theme from scratch, im using xampp as a local server and wordpress 4.3, the problem comes when i click on "customize" and change the header image, then i click "save and publish" but i still have the last image i had and the changes i made from the customize menu dont take effect some times. here is the current code i have:
functions.php
register_default_headers( array(
'logo1' => array(
'url' => '%s/images/logo1.jpg',
'thumbnail_url' => '%s/images/logo1.jpg',
'description' => __( 'Wheel', 'twentyeleven' )
),
'logo2' => array(
'url' => '%s/images/logo2.jpg',
'thumbnail_url' => '%s/images/logo2.jpg',
'description' => __( 'Shore', 'twentyeleven' )
),
'logo3' => array(
'url' => '%s/images/logo3.jpg',
'thumbnail_url' => '%s/images/logo3.jpg',
'description' => __( 'Trolley', 'twentyeleven' )
)
) );
add_theme_support("custom-header");
it works fine until i click on save and publish, sometimes it dont take effect and dont save and sometimes it works, but other options like changing the background image or color of the page works well. thank you!!

Genesis Start Theme remove services post type

I'm trying to remove the services post type in the Start Genesis child theme. The Start theme comes bundled with a services post type. I have a page with the URL -- http://domain.com/services -- but when I try to the view the page on this url, I am greeted with a 404 not found yet I know this page exists and has content.
Now for SEO reasons this is the best URL for this page so changing it is not an option.
To my question, is there a way to remove the services post type in the Start theme?
Thanks
Try this..
function custom_unregister_theme_post_types() {
global $wp_post_types;
if ( isset( $wp_post_types[ 'services' ] ) ) {
unset( $wp_post_types[ 'services' ] );
}
}
add_action( 'init', 'custom_unregister_theme_post_types', 20 );
Note : Please make a back up of your database before trying.
For anyone having the same issue, response from the theme author regarding the "services" post type
There's a custom post type "Services" and /services/ url will load the archive page of services post type which conflicts with your page.
If you don't use services post type, you can remove that in zp_cpt.php file ( the file is in /include/cpt/ folder ).
In the file, remove or comment out this code
$services_custom_default = array('supports' => array( 'title', 'editor','thumbnail', 'revisions' ),'menu_icon' => get_stylesheet_directory_uri().'/include/cpt/images/portfolio.png',);
$services = new Super_Custom_Post_Type( 'services', 'Service', 'Services', $services_custom_default );
$services->add_meta_box( array('id' => 'services_settings','context' => 'normal','fields' => array('icon_type' => array( 'type' => 'select', 'options' => array('font-awesome' => 'Font-Awesome','glyphicons' => 'Glyphicons', 'image' => 'Image' ), 'data-zp_desc' => __( 'Select icons to use. Font-Awesome, Glyphicons or an Image.','start') ),'icon_class' => array( 'type' => 'text','data-zp_desc' => __( 'Add icon classes. For font-awesome classes, please refer to this link page. For Glyphicons, refer to this page ','start') ),'icon_link' => array( 'type' => 'text', 'data-zp_desc' => __( 'Service item link','start') ),'icon_target' => array( 'type' => 'select', 'options' => array('_blank' => '_blank','_self' => '_self', '_parent' => '_parent' ), 'data-zp_desc' => __( 'Target','start') ),)
) );

Categories