Advertisement
Guest User

sunset-theme

a guest
Oct 13th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.93 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. // in functions-admin.php
  5. // ==================
  6. // we can get all the post formats by get_post_format_slugs() function
  7. // it returns all formats including 'standard' format which we don't need
  8. // 'standard' is always on the top so its index is zero
  9. // so we can ignore it by a if condition if( $i != 0)
  10.  
  11. function post_formats_callback() {
  12.  
  13.     $formats = get_post_format_slugs();
  14.     $options =  get_option( 'post_formats' );
  15.     $output = '';
  16.     $i = 0;
  17.  
  18.     foreach( $formats as $format ) {
  19.  
  20.         if( $i != 0) {
  21.  
  22.             $checked = ( @$options[$format] == $format ? 'checked' : '' );
  23.             $output .= '<label><input type="checkbox" name="post_formats['.$format.']" '.$checked.' value="'.$format.'">' . $format . "</label><br>";
  24.             }
  25.             $i++;      
  26.     }
  27.     echo $output;
  28. }
  29.  
  30.  
  31. // in theme-support.php
  32. // =================
  33. $options =  get_option( 'post_formats' );
  34. if( ! empty( $options ) ){
  35.     add_theme_support( 'post-formats', $options );
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement