Skip to content

Instantly share code, notes, and snippets.

@yuliyang
Created January 9, 2023 13:01
Show Gist options
  • Save yuliyang/c4e543e431da407d175e3bb93f7bef30 to your computer and use it in GitHub Desktop.
Save yuliyang/c4e543e431da407d175e3bb93f7bef30 to your computer and use it in GitHub Desktop.
[ WordPress Blocks ] Register blocks + custom number list style + respect list start number
<?php
if ( function_exists( 'register_block_style' ) ) {
register_block_style(
'core/list',
array(
'name' => 'ds-number',
'label' => __( 'Number List', 'dejavu' ),
'is_default' => false,
)
);
}
add_action('wp_footer', 'dejavu_inline_script');
function dejavu_inline_script()
{
if (is_singular('recipe')) {
?>
<script>
jQuery(document).ready(function($) {
jQuery( ".is-style-ds-number" ).each(function() {
var val=1;
if ( jQuery(this).attr("start")){
val = jQuery(this).attr("start");
}
val=val-1;
val= 'ds-number-counter '+ val;
jQuery(this).css('counter-increment',val );
});
});
</script>
<?php
}
}
.is-style-ds-number {
counter-reset: ds-number-counter;
list-style: none;
margin: 0;
font-weight: 400;
}
.is-style-ds-number > li {
padding: 20px 0 20px 56px;
counter-increment: ds-number-counter;
position: relative;
line-height: 28px;
}
.is-style-ds-number > li::before {
content: counter(ds-number-counter);
color: #ffffff;
font-size: 20px;
font-weight: bold;
font-family: "Montserrat", sans-serif;
position: absolute;
--size: 32px;
left: 0;
line-height: var(--size);
width: var(--size);
height: var(--size);
top: 18px;
background: #B25022;
border-radius: 50%;
text-align: center;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment