Im building my own wordperss theme and when starting on the WordPress Customizer for theme options I have come in a little bit of trouble.
Basically im trying to create a textarea and what I have read I need to create a extended class and then call it under the add_control function of WordPress.
I have tried this and all works well in customizer mode but as soon as I enter any other part of the site I get this error:
Fatal error: Class ‘WP_Customize_Control’ not found
As I say it works 100% within the customizer it’s self but any other page including admin I get this message.
Here is the class:
class ublxlportfolio_textarea extends WP_Customize_Control {
public $type = 'textarea';
public function render_content() {
?>
<label>
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
<textarea rows="5" style="width:100%;" <?php $this->link(); ?>><?php echo esc_textarea( $this->value() ); ?></textarea>
</label>
<?php
}
}
Do I need to wrap it in a conditional tag? If so what would that be??
Am I doing this all wrong?
To clarify @Robert’s correct answer:
Class WP_Customize_Control is loaded only when theme customizer is acutally used. So, you need to define your class within function bind to ‘customize_register’ action.
Example:
You need the following line before the class definition:
I had the same issue and landed here from Google, hope this help someone!
Found out that the class needs to come within the register function!
Reminder: In case if you just forgot to check if WP_Customize_Control class exists or not while extending it. This reminder might help you to debug this issue if you are in the page where theme customizer is not used; Since Class WP_Customize_Control is loaded only when theme customizer is actually used.
Cheers!