Selective refresh in the customizer css value does not work
I'm experiencing difficulties with a theme I developed.
I'm using Envato, where I cannot enter CSS anywhere other than wp_add_inline_style();
or enqueue style
.
I use preview customization directly and add partial refresh.
I have a settings menu with the following options:
- choice of layout A or B
- choice of layout background color
The problem is that the layout changes when the background color is changed.
Does anyone have a solution?
Code snippet: customizer.php
function customizer_nav( $wp_customize ) {
// Section
$wp_customize->add_section( 'navigasi_sett',
array(
'title' => __( 'Navigasi Primary', 'mocita' ),
'priority' => 100,
'panel' => 'primary_panel',
)
);
// Background
$wp_customize->add_setting( 'nav_background',
array(
'default' => '#0663cc',
'transport' => 'postMessage',
'sanitize_callback' => 'sanitize_hex_color',
)
);
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'nav_background',
array(
'label' => __( 'Background Menus', 'mocita' ),
'section' => 'navigasi_sett',
'settings' => 'nav_background',
)
));
// Navigasi layout
$wp_customize->add_setting( 'nav_layout',
array(
'default' => 'tes1',
'transport' => 'postMessage',
'sanitize_callback' => 'mocita_sanitize_radio_img',
)
);
$wp_customize->add_control( new Mocita_Image_Radio( $wp_customize, 'nav_layout',
array(
'label' => __( 'Navigasi Layout', 'mocita' ),
'section' => 'navigasi_sett',
'choices' => array(
'tes1' => array(
'image' => trailingslashit( get_template_directory_uri() ) . 'images/navigasi/tes1.png',
'name' => __( 'tes1', 'mocita' )
),
'tes2' => array(
'image' => trailingslashit( get_template_directory_uri() ) . 'images/navigasi/tes2.png',
'name' => __( 'tes2', 'mocita' )
)
)
)
));
}
// selevtive_refresh
if ( isset( $wp_customize->selective_refresh ) ) {
// Navigasi Layout
$wp_customize->selective_refresh->add_partial( 'nav_layout',
array(
'selector' => '#primary',
'container_inclusive' => false,
'render_callback' => 'nav_layout',
)
);
}
// callback nav_layout
function nav_layout() {
$layout = get_theme_mod( 'nav_layout', 'nav1' );
if ( $layout === 'nav1' ) {
get_template_part( 'template-parts/navigasi/navigasi', 'primary1' );
} elseif ( $layout === 'nav2' ) {
get_template_part( 'template-parts/navigasi/navigasi', 'primary2' );
}
}
?>
customize-preview.js
(function( $ ) {
// ( Navigasi ) Background
wp.customize( 'nav_background', function( value ) {
value.bind( function( to ) {
$( '#menu' ).css( 'background', to );
});
});
} )( jQuery );
css wordpress
add a comment |
I'm experiencing difficulties with a theme I developed.
I'm using Envato, where I cannot enter CSS anywhere other than wp_add_inline_style();
or enqueue style
.
I use preview customization directly and add partial refresh.
I have a settings menu with the following options:
- choice of layout A or B
- choice of layout background color
The problem is that the layout changes when the background color is changed.
Does anyone have a solution?
Code snippet: customizer.php
function customizer_nav( $wp_customize ) {
// Section
$wp_customize->add_section( 'navigasi_sett',
array(
'title' => __( 'Navigasi Primary', 'mocita' ),
'priority' => 100,
'panel' => 'primary_panel',
)
);
// Background
$wp_customize->add_setting( 'nav_background',
array(
'default' => '#0663cc',
'transport' => 'postMessage',
'sanitize_callback' => 'sanitize_hex_color',
)
);
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'nav_background',
array(
'label' => __( 'Background Menus', 'mocita' ),
'section' => 'navigasi_sett',
'settings' => 'nav_background',
)
));
// Navigasi layout
$wp_customize->add_setting( 'nav_layout',
array(
'default' => 'tes1',
'transport' => 'postMessage',
'sanitize_callback' => 'mocita_sanitize_radio_img',
)
);
$wp_customize->add_control( new Mocita_Image_Radio( $wp_customize, 'nav_layout',
array(
'label' => __( 'Navigasi Layout', 'mocita' ),
'section' => 'navigasi_sett',
'choices' => array(
'tes1' => array(
'image' => trailingslashit( get_template_directory_uri() ) . 'images/navigasi/tes1.png',
'name' => __( 'tes1', 'mocita' )
),
'tes2' => array(
'image' => trailingslashit( get_template_directory_uri() ) . 'images/navigasi/tes2.png',
'name' => __( 'tes2', 'mocita' )
)
)
)
));
}
// selevtive_refresh
if ( isset( $wp_customize->selective_refresh ) ) {
// Navigasi Layout
$wp_customize->selective_refresh->add_partial( 'nav_layout',
array(
'selector' => '#primary',
'container_inclusive' => false,
'render_callback' => 'nav_layout',
)
);
}
// callback nav_layout
function nav_layout() {
$layout = get_theme_mod( 'nav_layout', 'nav1' );
if ( $layout === 'nav1' ) {
get_template_part( 'template-parts/navigasi/navigasi', 'primary1' );
} elseif ( $layout === 'nav2' ) {
get_template_part( 'template-parts/navigasi/navigasi', 'primary2' );
}
}
?>
customize-preview.js
(function( $ ) {
// ( Navigasi ) Background
wp.customize( 'nav_background', function( value ) {
value.bind( function( to ) {
$( '#menu' ).css( 'background', to );
});
});
} )( jQuery );
css wordpress
Can you add the navigation color in style.css with !important;?
– Su Yatanar
Dec 31 '18 at 1:37
sure ... but it doesn't work in customize-preview
– dabi
Dec 31 '18 at 4:55
add a comment |
I'm experiencing difficulties with a theme I developed.
I'm using Envato, where I cannot enter CSS anywhere other than wp_add_inline_style();
or enqueue style
.
I use preview customization directly and add partial refresh.
I have a settings menu with the following options:
- choice of layout A or B
- choice of layout background color
The problem is that the layout changes when the background color is changed.
Does anyone have a solution?
Code snippet: customizer.php
function customizer_nav( $wp_customize ) {
// Section
$wp_customize->add_section( 'navigasi_sett',
array(
'title' => __( 'Navigasi Primary', 'mocita' ),
'priority' => 100,
'panel' => 'primary_panel',
)
);
// Background
$wp_customize->add_setting( 'nav_background',
array(
'default' => '#0663cc',
'transport' => 'postMessage',
'sanitize_callback' => 'sanitize_hex_color',
)
);
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'nav_background',
array(
'label' => __( 'Background Menus', 'mocita' ),
'section' => 'navigasi_sett',
'settings' => 'nav_background',
)
));
// Navigasi layout
$wp_customize->add_setting( 'nav_layout',
array(
'default' => 'tes1',
'transport' => 'postMessage',
'sanitize_callback' => 'mocita_sanitize_radio_img',
)
);
$wp_customize->add_control( new Mocita_Image_Radio( $wp_customize, 'nav_layout',
array(
'label' => __( 'Navigasi Layout', 'mocita' ),
'section' => 'navigasi_sett',
'choices' => array(
'tes1' => array(
'image' => trailingslashit( get_template_directory_uri() ) . 'images/navigasi/tes1.png',
'name' => __( 'tes1', 'mocita' )
),
'tes2' => array(
'image' => trailingslashit( get_template_directory_uri() ) . 'images/navigasi/tes2.png',
'name' => __( 'tes2', 'mocita' )
)
)
)
));
}
// selevtive_refresh
if ( isset( $wp_customize->selective_refresh ) ) {
// Navigasi Layout
$wp_customize->selective_refresh->add_partial( 'nav_layout',
array(
'selector' => '#primary',
'container_inclusive' => false,
'render_callback' => 'nav_layout',
)
);
}
// callback nav_layout
function nav_layout() {
$layout = get_theme_mod( 'nav_layout', 'nav1' );
if ( $layout === 'nav1' ) {
get_template_part( 'template-parts/navigasi/navigasi', 'primary1' );
} elseif ( $layout === 'nav2' ) {
get_template_part( 'template-parts/navigasi/navigasi', 'primary2' );
}
}
?>
customize-preview.js
(function( $ ) {
// ( Navigasi ) Background
wp.customize( 'nav_background', function( value ) {
value.bind( function( to ) {
$( '#menu' ).css( 'background', to );
});
});
} )( jQuery );
css wordpress
I'm experiencing difficulties with a theme I developed.
I'm using Envato, where I cannot enter CSS anywhere other than wp_add_inline_style();
or enqueue style
.
I use preview customization directly and add partial refresh.
I have a settings menu with the following options:
- choice of layout A or B
- choice of layout background color
The problem is that the layout changes when the background color is changed.
Does anyone have a solution?
Code snippet: customizer.php
function customizer_nav( $wp_customize ) {
// Section
$wp_customize->add_section( 'navigasi_sett',
array(
'title' => __( 'Navigasi Primary', 'mocita' ),
'priority' => 100,
'panel' => 'primary_panel',
)
);
// Background
$wp_customize->add_setting( 'nav_background',
array(
'default' => '#0663cc',
'transport' => 'postMessage',
'sanitize_callback' => 'sanitize_hex_color',
)
);
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'nav_background',
array(
'label' => __( 'Background Menus', 'mocita' ),
'section' => 'navigasi_sett',
'settings' => 'nav_background',
)
));
// Navigasi layout
$wp_customize->add_setting( 'nav_layout',
array(
'default' => 'tes1',
'transport' => 'postMessage',
'sanitize_callback' => 'mocita_sanitize_radio_img',
)
);
$wp_customize->add_control( new Mocita_Image_Radio( $wp_customize, 'nav_layout',
array(
'label' => __( 'Navigasi Layout', 'mocita' ),
'section' => 'navigasi_sett',
'choices' => array(
'tes1' => array(
'image' => trailingslashit( get_template_directory_uri() ) . 'images/navigasi/tes1.png',
'name' => __( 'tes1', 'mocita' )
),
'tes2' => array(
'image' => trailingslashit( get_template_directory_uri() ) . 'images/navigasi/tes2.png',
'name' => __( 'tes2', 'mocita' )
)
)
)
));
}
// selevtive_refresh
if ( isset( $wp_customize->selective_refresh ) ) {
// Navigasi Layout
$wp_customize->selective_refresh->add_partial( 'nav_layout',
array(
'selector' => '#primary',
'container_inclusive' => false,
'render_callback' => 'nav_layout',
)
);
}
// callback nav_layout
function nav_layout() {
$layout = get_theme_mod( 'nav_layout', 'nav1' );
if ( $layout === 'nav1' ) {
get_template_part( 'template-parts/navigasi/navigasi', 'primary1' );
} elseif ( $layout === 'nav2' ) {
get_template_part( 'template-parts/navigasi/navigasi', 'primary2' );
}
}
?>
customize-preview.js
(function( $ ) {
// ( Navigasi ) Background
wp.customize( 'nav_background', function( value ) {
value.bind( function( to ) {
$( '#menu' ).css( 'background', to );
});
});
} )( jQuery );
css wordpress
css wordpress
edited Dec 31 '18 at 6:58
Laurens Deprost
978114
978114
asked Dec 30 '18 at 23:47
dabidabi
1
1
Can you add the navigation color in style.css with !important;?
– Su Yatanar
Dec 31 '18 at 1:37
sure ... but it doesn't work in customize-preview
– dabi
Dec 31 '18 at 4:55
add a comment |
Can you add the navigation color in style.css with !important;?
– Su Yatanar
Dec 31 '18 at 1:37
sure ... but it doesn't work in customize-preview
– dabi
Dec 31 '18 at 4:55
Can you add the navigation color in style.css with !important;?
– Su Yatanar
Dec 31 '18 at 1:37
Can you add the navigation color in style.css with !important;?
– Su Yatanar
Dec 31 '18 at 1:37
sure ... but it doesn't work in customize-preview
– dabi
Dec 31 '18 at 4:55
sure ... but it doesn't work in customize-preview
– dabi
Dec 31 '18 at 4:55
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53982369%2fselective-refresh-in-the-customizer-css-value-does-not-work%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53982369%2fselective-refresh-in-the-customizer-css-value-does-not-work%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you add the navigation color in style.css with !important;?
– Su Yatanar
Dec 31 '18 at 1:37
sure ... but it doesn't work in customize-preview
– dabi
Dec 31 '18 at 4:55