Created
January 9, 2023 13:01
-
-
Save yuliyang/c4e543e431da407d175e3bb93f7bef30 to your computer and use it in GitHub Desktop.
[ WordPress Blocks ] Register blocks + custom number list style + respect list start number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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