/*
Theme Name:           Flatsome
Theme URI:            http://flatsome.uxthemes.com
Author:               UX-Themes
Author URI:           https://uxthemes.com
Description:          Multi-Purpose Responsive WooCommerce Theme
Version:              3.17.1
Requires at least:    5.4.0
Requires PHP:         5.6.20
WC requires at least: 4.7.0
Text Domain:          flatsome
License:              https://themeforest.net/licenses
License URI:          https://themeforest.net/licenses
*/


/***************
All custom CSS should be added to Flatsome > Advanced > Custom CSS,
or in the style.css of a Child Theme.
***************/


add_action('flatsome_before_blog', 'add_rankmath_breadcrumbs');
add_action('flatsome_before_page', 'add_rankmath_breadcrumbs');
function add_rankmath_breadcrumbs(){
 
if (function_exists('rank_math_the_breadcrumbs') && !is_front_page()){
?>
<div id="page-breadcrumbs" class="container">
<?php rank_math_the_breadcrumbs(); ?>
</div>
<?php
}
}

add_post_type_support('post', 'custom-fields');

function register_rank_math_meta_to_rest() {

    // ----- POST -----
    register_post_meta(
        'post', 
        'rank_math_title',
        [
            'show_in_rest' => true,
            'type'         => 'string',
            'single'       => true,
            'auth_callback' => function() { return current_user_can('edit_posts'); },
        ]
    );

    register_post_meta(
        'post',
        'rank_math_focus_keyword',
        [
            'show_in_rest' => true,
            'type'         => 'string',
            'single'       => true,
            'auth_callback' => function() { return current_user_can('edit_posts'); },
        ]
    );

    register_post_meta(
        'post',
        'rank_math_description',
        [
            'show_in_rest' => true,
            'type'         => 'string',
            'single'       => true,
            'auth_callback' => function() { return current_user_can('edit_posts'); },
        ]
    );

    // ----- PAGE -----
    register_post_meta(
        'page',
        'rank_math_title',
        [
            'show_in_rest' => true,
            'type'         => 'string',
            'single'       => true,
            'auth_callback' => function() { return current_user_can('edit_posts'); },
        ]
    );

    register_post_meta(
        'page',
        'rank_math_focus_keyword', // đã thêm tham số bị thiếu
        [
            'show_in_rest' => true,
            'type'         => 'string',
            'single'       => true,
            'auth_callback' => function() { return current_user_can('edit_posts'); },
        ]
    );

    register_post_meta(
        'page',
        'rank_math_description',
        [
            'show_in_rest' => true,
            'type'         => 'string',
            'single'       => true,
            'auth_callback' => function() { return current_user_can('edit_posts'); },
        ]
    );
}

add_action('init', 'register_rank_math_meta_to_rest');