Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*-----------------------------------------------*/
- /* KENTOOZ FRAMEWORK
- /* Version :1.01
- /* You can add your own function here!
- /* But don't change anything in this file!
- /*-----------------------------------------------*/
- function wpex_auto_add_link_titles( $content ) {
- // No need to do anything if there isn't any content
- if ( empty( $content ) ) {
- return $content;
- }
- // Define links array
- $links = array();
- libxml_use_internal_errors(true);
- // Get page content
- $html = new DomDocument;
- $html->loadHTML( $content );
- $html->preserveWhiteSpace = false;
- // Loop through all content links
- foreach( $html->getElementsByTagName( 'a' ) as $link ) {
- // If the title attribute is already defined no need to do anything
- if ( ! empty( $link->getAttribute( 'title' ) ) ) {
- continue;
- }
- // Get link text
- $link_text = $link->textContent;
- // Save links and link text in $links array
- if ( $link_text ) {
- $links[$link_text] = $link->getAttribute( 'href' );
- }
- }
- // Loop through links array and update post content to add link titles
- if ( ! empty( $links ) ) {
- foreach ( $links as $text => $link ) {
- if ( $link && $text ) {
- $text = esc_attr( $text ); // Sanitize
- $text = ucwords( $text ); // Captilize words (looks better imo)
- $replace = $link .'" title="'. $text .'"'; // Add title to link
- $content = str_replace( $link .'"', $replace, $content ); // Replace post content
- }
- }
- }
- // Return post content
- return $content;
- }
- add_filter( 'the_content', 'wpex_auto_add_link_titles' );
- //Add title and alt to image thubnail
- function isa_add_img_title( $attr, $attachment = null ) {
- $img_title = trim( strip_tags( $attachment->post_title ) );
- $attr['title'] = $img_title;
- $attr['description'] = $img_title;
- $attr['alt'] = $img_title;
- return $attr;
- }
- add_filter( 'wp_get_attachment_image_attributes','isa_add_img_title', 10, 2 );
- //Making jQuery to load from Google Library
- function replace_jquery() {
- if (!is_admin()) {
- // comment out the next two lines to load the local copy of jQuery
- wp_deregister_script('jquery');
- wp_register_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', false, '3.1.1');
- wp_enqueue_script('jquery');
- }
- }
- add_action('init', 'replace_jquery');
- //PHOTON
- add_filter( 'the_content', 'wpse39167_replace_image',9999 );
- function wpse39167_replace_image( $content )
- {
- $content = preg_replace_callback( "@@", 'wpse39167_maybe_replace_image', $content );
- return $content;
- }
- function wpse39167_maybe_replace_image($matches){
- if(!$matches[1])
- return $matches[0];
- $counter = wpse39167_static_counter( $matches[1] );
- $wp = 'http://i'.$counter.'.wp.com/';
- $url = str_replace(array('http://','https://'),$wp,$matches[1]);
- return str_replace($matches[1],$url,$matches[0]);
- }
- function wpse39167_static_counter( $url ) {
- srand( crc32( basename( $url ) ) );
- $static_counter = rand( 0, 2 );
- srand(); // this resets everything that relies on this, like array_rand() and shuffle()
- return $static_counter;
- }
- //HTML Sitemap: add [html-sitemap]
- function html_sitem_function($atts) {
- extract(shortcode_atts(array(
- 'append' => '',
- 'heading' => null,
- 'max' => 5000,
- 'cpt1' => null,
- 'cpt2' => null,
- 'cpt3' => null,
- ), $atts));
- $return_string = '<ul>';
- query_posts(array('post_type' => array('post', $cpt1, $cpt2, $cpt3), 'orderby' => 'type', 'order' => 'DESC', 'showposts' => $max, 'append' => $append, 'heading' => $heading));
- $return_string = '<h2>'.$heading.'</h2>';
- if (have_posts()) :
- while (have_posts()) : the_post();
- $return_string .= '<li><a href="'.get_permalink().''.$append.'/">'.get_the_title().'</a></li>';
- endwhile;
- endif;
- $return_string .= '</ul>';
- wp_reset_query();
- return $return_string;
- }
- function register_shortcode_html_sitemap(){
- add_shortcode('html-sitemap', 'html_sitem_function');
- }
- add_action( 'init', 'register_shortcode_html_sitemap');
- //ADD FILES To THEME
- function add_theme_scripts() {
- wp_enqueue_style( 'style', get_stylesheet_uri() );
- wp_enqueue_style( 'stylesheet', get_template_directory_uri() . '/custom.css', array(), '1.1', 'all');
- wp_enqueue_script( 'script', get_template_directory_uri() . '/customjs.php', array ( 'jquery' ), 1.1, true);
- if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
- wp_enqueue_script( 'comment-reply' );
- }
- }
- add_action( 'wp_enqueue_scripts', 'add_theme_scripts' );
- //Change Search URL
- function fb_change_search_url_rewrite() {
- if ( is_search() && ! empty( $_GET['s'] ) ) {
- wp_redirect( home_url( "/search/?q=" ) . urlencode( get_query_var( 's' ) ) );
- exit();
- }
- }
- add_action( 'template_redirect', 'fb_change_search_url_rewrite' );
- /* Change Excerpt length */
- function custom_excerpt_length( $length ) {
- return 70;
- }
- add_filter( ‘excerpt_length’, ‘custom_excerpt_length’, 999 );
- // Load kentooz framework
- require_once (TEMPLATEPATH . '/includes/init.php');
- $kentooz_declare = new KENTOOZ();
- $kentooz_declare->init();
- /*
- * Core infinite scroll jetpack
- * Since v.1.1.5
- */
- function ktz_infinite_scroll_init() {
- add_theme_support( 'infinite-scroll', array(
- 'type' => 'scroll',
- 'footer_widgets' => false,
- 'container' => 'ktz-infinitescroll-jetpack',
- 'wrapper' => true,
- 'render' => false,
- 'posts_per_page' => false,
- ) );
- }
- add_action( 'after_setup_theme', 'ktz_infinite_scroll_init' );
- ?>
Advertisement
Add Comment
Please, Sign In to add comment