Custom Block CSS not applied on front-end
-
Hello everyone
I am trying – and failing – to apply some CSS to a default block through function.php for my custom block theme.
More precisely, I want to modify the style of the search bar block to adjust the padding in the input field, and remove the space between the field and the button.
In function.php, I added this code :
if ( ! function_exists( 'theme_setup' ) ) :
function theme_setup() {
wp_enqueue_block_style(
'widgets/search',
array(
'handle' => 'search-bar',
'src' => get_theme_file_uri( 'assets/css/search-bar.css' ),
'ver' => wp_get_theme( get_template() )->get( 'Version' ),
'path' => get_theme_file_path( 'assets/css/search-bar.css' ),
)
);
}
endif;The search-bar.css file contains the following properties :
input.wp-block-search__input{
padding: 0px 18px;
border: solid 1px #8acb8a;
background-color: #8acb8a;
}
button.wp-block-search__button{
margin-left: 0;
}(the border and background-color properties here are just there to make the changes more visible to me)
To my surprise, the custom CSS is applied to the block when viewed in the editor (https://i.ibb.co/vBMCBc3/editor.png), but not on the front-end (https://i.ibb.co/1bmKNVV/front-end.png). I was under the impression that it should be the opposite.
I can’t seem to make my attempts work here. The fact that it works in the editor makes me think that I am on the right path, but I don’t know what I am doing wrong. Any idea ?
- You must be logged in to reply to this topic.