query("DELETE FROM $wpdb->postmeta WHERE meta_key LIKE 'jeuninfo_tictag_%'"); $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE 'jeuninfo_tictag_%'"); } /*------------------------------ BALISE DISCOVER IMAGES ------------------------------*/ add_action('wp_head','jict_discover_meta'); function jict_discover_meta(){ echo ''; } /*------------------------------ STOPWORDS ------------------------------*/ function jict_stopwords(){ return [ 'le','la','les','un','une','des','du','de','et','en','dans','sur','pour','avec','par' ]; } /*------------------------------ TAGS AUTOMATIQUES ------------------------------*/ add_action('save_post','jict_generate_tags'); function jict_generate_tags($post_id){ if (wp_is_post_revision($post_id)) return; $content = strtolower(strip_tags(get_post_field('post_content',$post_id))); $words = str_word_count($content,1); $tags=[]; $stop=jict_stopwords(); foreach($words as $w){ if(strlen($w)>5 && !in_array($w,$stop)){ $tags[]=$w; } } $tags=array_unique(array_slice($tags,0,10)); if(!empty($tags)){ wp_set_post_tags($post_id,$tags,true); } } /*------------------------------ ANCIENS ARTICLES ------------------------------*/ register_activation_hook(__FILE__,'jict_process_old_posts'); function jict_process_old_posts(){ $args=[ 'post_type'=>'post', 'posts_per_page'=>-1, 'post_status'=>'publish' ]; $q=new WP_Query($args); foreach($q->posts as $p){ jict_generate_tags($p->ID); } wp_reset_postdata(); } /*------------------------------ ARTICLES LIES ------------------------------*/ add_filter('the_content','jict_related'); function jict_related($content){ if(!is_single()) return $content; $tags=wp_get_post_tags(get_the_ID()); if(!$tags) return $content; $ids=[]; foreach($tags as $t){ $ids[]=$t->term_id; } $args=[ 'tag__in'=>$ids, 'post__not_in'=>[get_the_ID()], 'posts_per_page'=>4 ]; $q=new WP_Query($args); if(!$q->have_posts()) return $content; $html=''; wp_reset_postdata(); return $content.$html; } /*------------------------------ MAILLAGE INTERNE ------------------------------*/ add_filter('the_content','jict_autolink'); function jict_autolink($content){ if(!is_single()) return $content; $tags=wp_get_post_tags(get_the_ID()); foreach($tags as $tag){ $link=get_tag_link($tag->term_id); $pattern='/\b('.preg_quote($tag->name,'/').')\b/i'; $content=preg_replace($pattern,'$1',$content,1); } return $content; } /*------------------------------ SCHEMA NEWSARTICLE ------------------------------*/ add_action('wp_head','jict_schema'); function jict_schema(){ if(!is_single()) return; global $post; $image=get_the_post_thumbnail_url($post->ID,'full'); $data=[ "@context"=>"https://schema.org", "@type"=>"NewsArticle", "headline"=>get_the_title(), "datePublished"=>get_the_date('c'), "dateModified"=>get_the_modified_date('c'), "image"=>[$image], "author"=>[ "@type"=>"Organization", "name"=>"JeunInfo" ], "publisher"=>[ "@type"=>"Organization", "name"=>"JeunInfo", "logo"=>[ "@type"=>"ImageObject", "url"=>home_url('/logo.png') ] ] ]; echo ''; } /*------------------------------ SITEMAP TAGS ------------------------------*/ add_action('init','jict_tags_sitemap'); function jict_tags_sitemap(){ add_rewrite_rule('jeuninfo-tags-sitemap.xml$','index.php?jict_tags=1','top'); } add_filter('query_vars','jict_vars'); function jict_vars($vars){ $vars[]='jict_tags'; return $vars; } add_action('template_redirect','jict_render_tags_sitemap'); function jict_render_tags_sitemap(){ if(get_query_var('jict_tags')!=1) return; header("Content-Type:text/xml"); $tags=get_tags(); echo ''; echo ''; foreach($tags as $tag){ echo ''.get_tag_link($tag->term_id).''; } echo ''; exit; } /*------------------------------ CSS RESPONSIVE ------------------------------*/ add_action('wp_head','jict_css'); function jict_css(){ ?>