Advertisement
Guest User

Untitled

a guest
Sep 17th, 2016
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.35 KB | None | 0 0
  1. <?php
  2. function screendoor_enqueue_styles() {
  3.  
  4.     $parent_style = 'twentysixteen-style';
  5.  
  6.     wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
  7.     wp_enqueue_style( 'child-style',
  8.         get_stylesheet_directory_uri() . '/style.css',
  9.         array( $parent_style ),
  10.         wp_get_theme()->get('Version')
  11.     );
  12. }
  13. add_action( 'wp_enqueue_scripts', 'screendoor_enqueue_styles' );
  14.  
  15. // Custom favicon Function to Include
  16. function customfavicon_link() {
  17.     echo '<link rel="apple-touch-icon" sizes="180x180" href="' . get_stylesheet_directory_uri() . '/apple-touch-icon.png"/>' . "\n";
  18.     echo '<link rel="icon" type="image/png" href="' . get_stylesheet_directory_uri() . '/favicon-32x32.png" sizes="32x32"/>' . "\n";
  19.     echo '<link rel="icon" type="image/png" href="' . get_stylesheet_directory_uri() . '/favicon-16x16.png" sizes="16x16"/>' . "\n";
  20.     echo '<link rel="manifest" href="' . get_stylesheet_directory_uri() . '/manifest.json">' . "\n";
  21.     echo '<link rel="mask-icon" href="' . get_stylesheet_directory_uri() . '/safari-pinned-tab.svg" color="#5bbad5">' . "\n";
  22.     echo '<meta name="theme-color" content="#ffffff">' . "\n";
  23. }
  24. add_action( 'wp_head', 'customfavicon_link' );
  25.  
  26. // Custom filter function to modify default gallery shortcode output
  27. // Courtesy of http://robido.com/wordpress/wordpress-gallery-filter-to-modify-the-html-output-of-the-default-gallery-shortcode-and-style/
  28. function my_post_gallery( $output, $attr ) {
  29.  
  30.     // Initialize
  31.     global $post, $wp_locale;
  32.  
  33.     // Gallery instance counter
  34.     static $instance = 0;
  35.     $instance++;
  36.  
  37.     // Validate the author's orderby attribute
  38.     if ( isset( $attr['orderby'] ) ) {
  39.         $attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );
  40.         if ( ! $attr['orderby'] ) unset( $attr['orderby'] );
  41.     }
  42.  
  43.     // Get attributes from shortcode
  44.     extract( shortcode_atts( array(
  45.         'order'      => 'ASC',
  46.         'orderby'    => 'menu_order ID',
  47.         'id'         => $post->ID,
  48.         'itemtag'    => 'dl',
  49.         'icontag'    => 'dt',
  50.         'captiontag' => 'dd',
  51.         'columns'    => 3,
  52.         'size'       => 'thumbnail',
  53.         'include'    => '',
  54.         'exclude'    => ''
  55.     ), $attr ) );
  56.  
  57.     // Initialize
  58.     $id = intval( $id );
  59.     $attachments = array();
  60.     if ( $order == 'RAND' ) $orderby = 'none';
  61.  
  62.     if ( ! empty( $include ) ) {
  63.  
  64.         // Include attribute is present
  65.         $include = preg_replace( '/[^0-9,]+/', '', $include );
  66.         $_attachments = get_posts( array( 'include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby ) );
  67.  
  68.         // Setup attachments array
  69.         foreach ( $_attachments as $key => $val ) {
  70.             $attachments[ $val->ID ] = $_attachments[ $key ];
  71.         }
  72.  
  73.     } else if ( ! empty( $exclude ) ) {
  74.  
  75.         // Exclude attribute is present
  76.         $exclude = preg_replace( '/[^0-9,]+/', '', $exclude );
  77.  
  78.         // Setup attachments array
  79.         $attachments = get_children( array( 'post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby ) );
  80.     } else {
  81.         // Setup attachments array
  82.         $attachments = get_children( array( 'post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby ) );
  83.     }
  84.  
  85.     if ( empty( $attachments ) ) return '';
  86.  
  87.     // Filter gallery differently for feeds
  88.     if ( is_feed() ) {
  89.         $output = "\n";
  90.         foreach ( $attachments as $att_id => $attachment ) $output .= wp_get_attachment_link( $att_id, $size, true ) . "\n";
  91.         return $output;
  92.     }
  93.  
  94.     // Filter tags and attributes
  95.     $itemtag = tag_escape( $itemtag );
  96.     $captiontag = tag_escape( $captiontag );
  97.     $columns = intval( $columns );
  98.     $itemwidth = $columns > 0 ? floor( 100 / $columns ) : 100;
  99.     $float = is_rtl() ? 'right' : 'left';
  100.     $selector = "gallery-{$instance}";
  101.  
  102.     // Filter gallery CSS
  103.     $output = apply_filters( 'gallery_style', "
  104.        <style type='text/css'>
  105.            #{$selector} {
  106.                margin: auto;
  107.            }
  108.            #{$selector} .gallery-item {
  109.                float: {$float};
  110.                margin-top: 10px;
  111.                text-align: center;
  112.                width: {$itemwidth}%;
  113.            }
  114.            #{$selector} img {
  115.                border: 2px solid #cfcfcf;
  116.            }
  117.            #{$selector} .gallery-caption {
  118.                margin-left: 0;
  119.            }
  120.        </style>
  121.        <!-- see gallery_shortcode() in wp-includes/media.php -->
  122.        <div id='$selector' class='gallery galleryid-{$id}'>"
  123.     );
  124.  
  125.     // Iterate through the attachments in this gallery instance
  126.     $i = 0;
  127.     foreach ( $attachments as $id => $attachment ) {
  128.  
  129.         // Attachment link
  130.         $link = isset( $attr['link'] ) && 'file' == $attr['link'] ? wp_get_attachment_link( $id, $size, false, false ) : wp_get_attachment_link( $id, $size, true, false );
  131.  
  132.         // Start itemtag
  133.         $output .= "<{$itemtag} class='gallery-item large-4 columns'>";
  134.  
  135.         // icontag
  136.         $output .= "
  137.        <{$icontag} class='gallery-icon'>
  138.            $link
  139.        </{$icontag}>";
  140.  
  141.         $title = trim($attachment->post_title);
  142.  
  143.         if ( $title ) {
  144.  
  145.             // title
  146.             $output .= "
  147.            <{$captiontag} class='gallery-title'>
  148.                <h2>" . $title . "</h2>
  149.            </{$captiontag}>";
  150.  
  151.         }
  152.  
  153.         if ( $captiontag && trim( $attachment->post_excerpt ) ) {
  154.  
  155.             // captiontag
  156.             $output .= "
  157.            <{$captiontag} class='gallery-caption'>
  158.                " . wptexturize($attachment->post_excerpt) . "
  159.            </{$captiontag}>";
  160.  
  161.         }
  162.  
  163.         // End itemtag
  164.         $output .= "</{$itemtag}>";
  165.  
  166.         // Line breaks by columns set
  167.         if($columns > 0 && ++$i % $columns == 0) $output .= '<br style="clear: both">';
  168.  
  169.     }
  170.  
  171.     // End gallery output
  172.     $output .= "
  173.        <br style='clear: both;'>
  174.    </div>\n";
  175.  
  176.     return $output;
  177.  
  178. }
  179.  
  180. // Apply filter to default gallery shortcode
  181. add_filter( 'post_gallery', 'my_post_gallery', 10, 2 );
  182.  
  183. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement