get('Version')
);
}
add_action('wp_enqueue_scripts','blocksy_child_enqueue_styles');
/* ===============================
SEO META BOX
================================ */
function add_custom_seo_meta_box() {
add_meta_box(
'custom_seo_box_id',
'SEO Description & Custom Schema',
'render_custom_seo_box',
['post','page'],
'normal',
'high'
);
}
add_action('add_meta_boxes','add_custom_seo_meta_box');
function render_custom_seo_box($post){
wp_nonce_field('custom_seo_box_nonce_action','custom_seo_box_nonce');
$seo_desc = get_post_meta($post->ID,'_custom_seo_description',true);
$seo_schema = get_post_meta($post->ID,'_custom_seo_schema',true);
echo '
';
echo '';
}
/* ===============================
SAVE SEO DATA
================================ */
function save_custom_seo_meta_box($post_id){
if(!isset($_POST['custom_seo_box_nonce'])) return;
if(!wp_verify_nonce($_POST['custom_seo_box_nonce'],'custom_seo_box_nonce_action')) return;
if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
if(!current_user_can('edit_post',$post_id)) return;
if(isset($_POST['custom_seo_description'])){
update_post_meta(
$post_id,
'_custom_seo_description',
sanitize_textarea_field($_POST['custom_seo_description'])
);
}
if(isset($_POST['custom_seo_schema'])){
update_post_meta(
$post_id,
'_custom_seo_schema',
wp_unslash($_POST['custom_seo_schema'])
);
}
}
add_action('save_post','save_custom_seo_meta_box');
/* ===============================
SEO HEAD OUTPUT
================================ */
function custom_seo_head_output(){
if(is_front_page() || is_home()){
echo '';
return;
}
if(is_singular()){
global $post;
$desc = get_post_meta($post->ID,'_custom_seo_description',true);
if(empty($desc)){
$desc = wp_trim_words(
wp_strip_all_tags($post->post_content),
25
);
}
echo '';
}
}
add_action('wp_head','custom_seo_head_output',1);
/* ===============================
REMOVE SITE NAME FROM TITLE
================================ */
function jyastu_remove_site_name_from_title($title_parts){
if(is_singular()){
unset($title_parts['site']);
unset($title_parts['tagline']);
}
return $title_parts;
}
add_filter('document_title_parts','jyastu_remove_site_name_from_title');
/* ===============================
COMMENT ANTI-SPAM
================================ */
function jyastu_comment_antispam(){
if(!is_user_logged_in()){
$wpcookie = isset($_POST['wpcookie']) ? $_POST['wpcookie'] : '';
if(empty($wpcookie)){
wp_die("Reload page and try again.");
}
if($wpcookie !== "ok"){
wp_die("You submitted too fast.");
}
}
}
add_action('pre_comment_on_post','jyastu_comment_antispam');
function jyastu_comment_hidden_field($defaults){
$defaults['fields']['author'] .= '
';
return $defaults;
}
add_filter('comment_form_defaults','jyastu_comment_hidden_field');