Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elementor Typography Control Default Values #5022

Closed
gho5t7m opened this issue Jul 11, 2018 · 6 comments
Closed

Elementor Typography Control Default Values #5022

gho5t7m opened this issue Jul 11, 2018 · 6 comments
Labels
type/developer-api Indicates when a topic is related to the Developer API and Documentation.

Comments

@gho5t7m
Copy link

gho5t7m commented Jul 11, 2018

I'm developer and I want to add Typography Control with its default values for title (h3) to my widget.

$this->add_group_control(
	Group_Control_Typography::get_type(),
	[
		'name' => 'title_typography',
		'label' => __( 'Title Typography', 'my-plugin-domain' ),
		'scheme' => Scheme_Typography::TYPOGRAPHY_1,
		'selector' => '{{WRAPPER}} h3',
		'default' => [
		                       'font_weight' => '500',
		                       'font_family'  => 'Rubik',
                                       'font_size'      => '14px',
				   ]
	]
);

I want to enter all typography control default values as:
Font Family, Font Size, Font Weight, TextTransform, Font Style, Text Decoration, Line Height and Letter Spacing.

Please, help with this.

@gho5t7m gho5t7m closed this as completed Jul 11, 2018
@gho5t7m gho5t7m reopened this Jul 11, 2018
@bainternet
Copy link
Contributor

@gho5t7m

Typography control is a field control so it accepts a fields_options parameter where you can define individual settings to the controls inside the group control including a default value, ex:

$this->add_group_control(
	Group_Control_Typography::get_type(),
	[
		'name' => 'title_typography',
		'label' => __( 'Title Typography', 'my-plugin-domain' ),
		'scheme' => Scheme_Typography::TYPOGRAPHY_1,
		'selector' => '{{WRAPPER}} h3',
		'fields_options' => [
			// Inner control name
			'font_weight' => [
				// Inner control settings
				'default' => '500',
			],
			'font_family' => [
				'default' => 'Rubik',
			],
			'font_size'   => [
				'default' => '14px',
			],
		],
	]
);

But you should set the defaults in CSS like we do so you don't store default values in the database.

@bainternet bainternet added the type/developer-api Indicates when a topic is related to the Developer API and Documentation. label Jul 11, 2018
@pmallek
Copy link

pmallek commented Aug 4, 2018

Whole idea behind this solution is fine just provided example contain an error, you can't define:
'font_size' => [ 'default' => '14px', ],
This will cause error.

It should be:
'font_size' => [ 'default' => [ 'unit' => 'px', 'size' => 14 ] ]

@sabuz
Copy link

sabuz commented Jan 16, 2019

This is not loading the custom typography until you click on Typography edit icon. Any help?

@entrey
Copy link

entrey commented Jun 16, 2020

So, the solution i figured out is the following:

$this->add_group_control(
    Group_Control_Typography::get_type(),
    [
        'name' => 'title',
        'selector' => '{{WRAPPER}} .title',
        'fields_options' => [
            // first mimic the click on Typography edit icon
            'typography' => ['default' => 'yes'],
            // then redifine the Elementor defaults
            'font_size' => ['default' => ['size' => 22]],
            'font_weight' => ['default' => 600],
            'line_height' => ['default' => ['size' => 1]],
        ],
    ]
);

@yinjinit
Copy link

yinjinit commented May 8, 2021

@bainternet , why are the default values stored in database? Aren't they fetched when the page loads?

@Bhavna93
Copy link

how to add a new option (small caps) in Typography >> Transform drop down. Is there any hook in elementor to inject this option ? I am doing this with my custom elementor widget

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/developer-api Indicates when a topic is related to the Developer API and Documentation.
Projects
None yet
Development

No branches or pull requests

7 participants