Advertisement
michaellevelup

Activities category

Mar 21st, 2022
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.67 KB | None | 0 0
  1.  
  2. function post_excerpt_center(){
  3.     if ( is_post_type_archive() ) {
  4.     ?>
  5.     <script>
  6.     function countLines() {                          
  7.         const el =
  8.             document.querySelectorAll('.wp-block-post-excerpt__excerpt');
  9.            
  10.         el.forEach( function(excerpt){
  11.         var divHeight = excerpt.offsetHeight;
  12.         var para = window.getComputedStyle(excerpt);
  13.         var lineHeight = parseInt(para.getPropertyValue('line-height'));
  14.         var lines = divHeight / lineHeight;
  15.        
  16.         if ( lines <= 2 ) {
  17.             excerpt.style.textAlign = 'center';
  18.         }
  19.         });
  20.     }
  21.     countLines();
  22.     </script>
  23.     <?php
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement