dimaslanjaka

flatsimplebingits.functions

Mar 19th, 2017
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.84 KB | None | 0 0
  1. <?php
  2. /*-----------------------------------------------*/
  3. /* KENTOOZ FRAMEWORK
  4. /* Version :1.01
  5. /* You can add your own function here!
  6. /* But don't change anything in this file!
  7. /*-----------------------------------------------*/
  8.  
  9. function wpex_auto_add_link_titles( $content ) {
  10.  
  11.     // No need to do anything if there isn't any content
  12.     if ( empty( $content ) ) {
  13.         return $content;
  14.     }
  15.  
  16.     // Define links array
  17.     $links = array();
  18.     libxml_use_internal_errors(true);
  19.  
  20.     // Get page content
  21.     $html = new DomDocument;
  22.     $html->loadHTML( $content );
  23.     $html->preserveWhiteSpace = false;
  24.  
  25.     // Loop through all content links
  26.     foreach( $html->getElementsByTagName( 'a' ) as $link ) {
  27.  
  28.         // If the title attribute is already defined no need to do anything
  29.         if ( ! empty( $link->getAttribute( 'title' ) ) ) {
  30.             continue;
  31.         }
  32.  
  33.         // Get link text
  34.         $link_text = $link->textContent;
  35.  
  36.         // Save links and link text in $links array
  37.         if ( $link_text ) {
  38.             $links[$link_text] = $link->getAttribute( 'href' );
  39.         }
  40.  
  41.     }
  42.  
  43.     // Loop through links array and update post content to add link titles
  44.     if ( ! empty( $links ) ) {
  45.         foreach ( $links as $text => $link ) {
  46.             if ( $link && $text ) {
  47.                 $text    = esc_attr( $text ); // Sanitize
  48.                 $text    = ucwords( $text );  // Captilize words (looks better imo)
  49.                 $replace = $link .'" title="'. $text .'"'; // Add title to link
  50.                 $content = str_replace( $link .'"', $replace, $content ); // Replace post content
  51.             }
  52.  
  53.         }
  54.     }
  55.  
  56.     // Return post content
  57.     return $content;
  58.  
  59. }
  60. add_filter( 'the_content', 'wpex_auto_add_link_titles' );
  61.  
  62. //Add title and alt to image thubnail
  63. function isa_add_img_title( $attr, $attachment = null ) {
  64.  
  65.     $img_title = trim( strip_tags( $attachment->post_title ) );
  66.  
  67.     $attr['title'] = $img_title;
  68.     $attr['description'] = $img_title;
  69.     $attr['alt'] = $img_title;
  70.  
  71.     return $attr;
  72. }
  73. add_filter( 'wp_get_attachment_image_attributes','isa_add_img_title', 10, 2 );
  74.  
  75. //Making jQuery to load from Google Library
  76. function replace_jquery() {
  77.     if (!is_admin()) {
  78.         // comment out the next two lines to load the local copy of jQuery
  79.         wp_deregister_script('jquery');
  80.         wp_register_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', false, '3.1.1');
  81.         wp_enqueue_script('jquery');
  82.     }
  83. }
  84. add_action('init', 'replace_jquery');
  85.  
  86. //PHOTON
  87. add_filter( 'the_content', 'wpse39167_replace_image',9999 );
  88. function wpse39167_replace_image( $content )
  89. {
  90.     $content = preg_replace_callback( "@@", 'wpse39167_maybe_replace_image', $content );
  91.     return $content;
  92. }
  93.  
  94. function wpse39167_maybe_replace_image($matches){
  95.     if(!$matches[1])
  96.         return $matches[0];
  97.  
  98.     $counter = wpse39167_static_counter( $matches[1] );
  99.     $wp = 'http://i'.$counter.'.wp.com/';
  100.     $url = str_replace(array('http://','https://'),$wp,$matches[1]);
  101.     return str_replace($matches[1],$url,$matches[0]);
  102. }
  103.  
  104. function wpse39167_static_counter( $url ) {
  105.         srand( crc32( basename( $url ) ) );
  106.         $static_counter = rand( 0, 2 );
  107.         srand(); // this resets everything that relies on this, like array_rand() and shuffle()
  108.         return $static_counter;
  109.  
  110. }
  111.  
  112. //HTML Sitemap: add [html-sitemap]
  113. function html_sitem_function($atts) {
  114.  
  115.  
  116.  
  117.    extract(shortcode_atts(array(
  118.           'append' => '',
  119.           'heading' => null,
  120.           'max' => 5000,
  121.           'cpt1' => null,
  122.           'cpt2' => null,
  123.           'cpt3' => null,
  124. ), $atts));
  125.  
  126.  
  127.    $return_string = '<ul>';
  128.    query_posts(array('post_type' => array('post', $cpt1, $cpt2, $cpt3), 'orderby' => 'type', 'order' => 'DESC', 'showposts' => $max, 'append' => $append, 'heading' => $heading));
  129.   $return_string = '<h2>'.$heading.'</h2>';
  130.  if (have_posts()) :
  131.       while (have_posts()) : the_post();
  132.  
  133.         $return_string .= '<li><a href="'.get_permalink().''.$append.'/">'.get_the_title().'</a></li>';
  134.          
  135.          
  136.          
  137.          
  138.       endwhile;
  139.    endif;
  140.    $return_string .= '</ul>';
  141.  
  142.    wp_reset_query();
  143.    return $return_string;
  144.  
  145. }
  146.  
  147. function register_shortcode_html_sitemap(){
  148.  
  149.    add_shortcode('html-sitemap', 'html_sitem_function');
  150.  
  151. }
  152. add_action( 'init', 'register_shortcode_html_sitemap');
  153.  
  154. //ADD FILES To THEME
  155. function add_theme_scripts() {
  156.   wp_enqueue_style( 'style', get_stylesheet_uri() );
  157.  
  158.   wp_enqueue_style( 'stylesheet', get_template_directory_uri() . '/custom.css', array(), '1.1', 'all');
  159.  
  160.   wp_enqueue_script( 'script', get_template_directory_uri() . '/customjs.php', array ( 'jquery' ), 1.1, true);
  161.  
  162.     if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  163.       wp_enqueue_script( 'comment-reply' );
  164.     }
  165. }
  166. add_action( 'wp_enqueue_scripts', 'add_theme_scripts' );
  167.  
  168.  
  169. //Change Search URL
  170. function fb_change_search_url_rewrite() {
  171.     if ( is_search() && ! empty( $_GET['s'] ) ) {
  172.         wp_redirect( home_url( "/search/?q=" ) . urlencode( get_query_var( 's' ) ) );
  173.         exit();
  174.     }  
  175. }
  176. add_action( 'template_redirect', 'fb_change_search_url_rewrite' );
  177.  
  178. /* Change Excerpt length */
  179. function custom_excerpt_length( $length ) {
  180. return 70;
  181. }
  182. add_filter( ‘excerpt_length’, ‘custom_excerpt_length’, 999 );
  183.  
  184. // Load kentooz framework
  185. require_once (TEMPLATEPATH . '/includes/init.php');
  186. $kentooz_declare = new KENTOOZ();
  187. $kentooz_declare->init();
  188.  
  189. /*
  190.  * Core infinite scroll jetpack
  191.  * Since v.1.1.5
  192.  */
  193. function ktz_infinite_scroll_init() {
  194.     add_theme_support( 'infinite-scroll', array(
  195.         'type'           => 'scroll',
  196.         'footer_widgets' => false,
  197.         'container'      => 'ktz-infinitescroll-jetpack',
  198.         'wrapper'        => true,
  199.         'render'         => false,
  200.         'posts_per_page' => false,
  201.     ) );
  202. }
  203. add_action( 'after_setup_theme', 'ktz_infinite_scroll_init' );
  204. ?>
Advertisement
Add Comment
Please, Sign In to add comment