term_id);
$keyword = $tag->name;
$cleankeyword = stripslashes($keyword);
$url = ''.addcslashes($cleankeyword, '$').'';
$regEx = '\'(?!((<.*?)|(]*?)>)|([^>]*?))\'s';
$content = preg_replace($regEx, $url, $content, gdk_option('gdk_tag_num') ?? 5);
}
}
return $content;
}
add_filter('the_content', 'gdk_tag_link', 1);
}
// 自动添加nofloow
if(gdk_option('gdk_nofollow')) {
add_filter('the_content', 'gdk_nofollow');
add_filter('the_excerpt', 'gdk_nofollow');
function gdk_nofollow($content) {
return preg_replace_callback('/]+/', 'gdk_nofollow_callback', $content);
}
function gdk_nofollow_callback($matches) {
$link = $matches[0];
$site_link = get_bloginfo('url');
if (strpos($link, 'rel') === false) {
$link = preg_replace("%(href=\S(?!$site_link))%i", 'rel="nofollow" $1', $link);
} elseif (preg_match("%href=\S(?!$site_link)%i", $link)) {
$link = preg_replace('/rel=\S(?!nofollow)\S*/i', 'rel="nofollow"', $link);
}
return $link;
}
}
//百度主动推送
if (gdk_option('gdk_baidu_push')) {
function gdk_baidu_submit($post_ID) {
global $post;
$bd_submit_site = get_bloginfo('url');
$bd_submit_token = gdk_option('gdk_baidu_token');
if (empty($post_ID) || empty($bd_submit_site) || empty($bd_submit_token)) return;
if (get_post_meta($post_ID, 'gdk_baidu_submit', true) == 1) return;
$url = get_permalink($post_ID);
$api = $api = 'http://data.zz.baidu.com/urls?site='.$bd_submit_site.'&token='.$bd_submit_token;
$status = $post->post_status;
if ($status != '' && $status != 'publish') {
$request = new WP_Http;
$result = $request->request($api, array(
'method' => 'POST',
'body' => $url,
'headers' => 'Content-Type: text/plain'
));
if ( is_array( $result ) && !is_wp_error($result) && $result['response']['code'] == '200' ) {
error_log('baidu_submit_result:'.$result['body']);
$result = json_decode($result['body'], true);
}
if (array_key_exists('success', $result)) {
add_post_meta($post_ID, 'gdk_baidu_submit', 1, true);
}
}
}
add_action('publish_post', 'gdk_baidu_submit', 0);
add_action('wp_footer', 'gdk_baidu_auto_push', 500);
}
//百度自动推送
function gdk_baidu_auto_push() {
echo '';
}
if(gdk_option('gdk_seo_img')) {
//给文章图片自动添加alt和title信息
function gdk_imagesalt($content) {
global $post;
$pattern ="//i";
$replacement = '';
$content = preg_replace($pattern, $replacement, $content);
return $content;
}
add_filter('the_content', 'gdk_imagesalt');
function gdk_image_alt_tag($content) {
global $post;
preg_match_all('//', $content, $images);
if(!is_null($images)) {
foreach($images[1] as $index => $value) {
$new_img = str_replace('ID)) {
foreach (get_the_tags($post->ID) as $tag) $keywords.= $tag->name . ', ';
}
foreach (get_the_category($post->ID) as $category) $keywords.= $category->cat_name . ', ';
$keywords = substr_replace($keywords, '', -2);
} elseif (is_home()||is_front_page()) {
$keywords = gdk_option('gdk_keywords');
} elseif (is_tag()) {
if(in_string(tag_description(),'@@')) {
$keywords = gdk_term_meta('tag','keyword');
} else {
$keywords = single_tag_title('', false);
}
} elseif (is_category()) {
if(in_string(category_description(),'@@')) {
$keywords = gdk_term_meta('cat','keyword');
} else {
$keywords = single_cat_title('', false);
}
} elseif (is_search()) {
$keywords = esc_html($s, 1);
} else {
$keywords = trim(wp_title('', false));
}
if ($keywords) {
echo "\n";
}
}
add_action('wp_head', 'gdk_keywords');
//网站描述
function gdk_description() {
global $s, $post;
$description = '';
$blog_name = get_bloginfo('name');
$excerpt = $post->post_excerpt;
if (is_singular()) {
if (!empty($excerpt)) {
$text = $excerpt;
} else {
$text = strip_shortcodes($post->post_content);
}
$description = trim(str_replace(array(
"\r\n",
"\r",
"\n",
" ",
" "
) , " ", str_replace("\"", "'", strip_tags($text))));
if (!($description)) $description = $blog_name . "-" . trim(wp_title('', false));
} elseif (is_home()||is_front_page()) {
$description = gdk_option('gdk_description');// 首頁要自己加
} elseif (is_tag()) {
if(in_string(tag_description(),'@@')) {
$description = $blog_name . "'" . gdk_term_meta('tag','des') . "'";
} else {
$description = $blog_name . "'" . single_tag_title('', false) . "'";
}
} elseif (is_category()) {
if(in_string(category_description(),'@@')) {
$description = $blog_name . "'" . trim(strip_tags(gdk_term_meta('tag','des')));
} else {
$description = $blog_name . "'" . trim(strip_tags(category_description()));
}
} elseif (is_archive()) {
$description = $blog_name . "'" . trim(wp_title('', false)) . "'";
} elseif (is_search()) {
$description = $blog_name . ": '" . esc_html($s, 1) . "' 的搜索結果";
} else {
$description = $blog_name . "'" . trim(wp_title('', false)) . "'";
}
$description = mb_substr($description, 0, 220, 'utf-8');
echo "\n";
}
add_action('wp_head', 'gdk_description');
//添加Open Graph Meta
function meta_og() {
global $post;
if ( is_single() ) {
if( has_post_thumbnail( $post->ID ) ) {
$img_src = gdk_thumbnail_src();
}
$excerpt = strip_tags( $post->post_content );
$excerpt_more = '';
if ( strlen($excerpt ) > 155) {
$excerpt = substr( $excerpt,0,155 );
$excerpt_more = ' ...';
}
$excerpt = str_replace( '"', '', $excerpt );
$excerpt = str_replace( "'", '', $excerpt );
$excerptwords = preg_split( '/[\n\r\t ]+/', $excerpt, -1, PREG_SPLIT_NO_EMPTY );
array_pop( $excerptwords );
$excerpt = implode( ' ', $excerptwords ) . $excerpt_more;
?>
1) {
echo "\n";
echo "\n";
echo "";
}
}
add_action('wp_head', 'gdk_canonical');