@charset "UTF-8";
/*
    Template: swell
    Theme Name: SWELL CHILD
    Theme URI: https://swell-theme.com/
    Description: SWELLの子テーマ
    Version: 1.0.0
    Author: LOOS WEB STUDIO
    Author URI: https://loos-web-studio.com/

    License: GNU General Public License
    License URI: http://www.gnu.org/licenses/gpl.html
*/
function add_breadcrumb_structured_data() {
  if (is_single()) {
    global $post;
    $title = get_the_title($post->ID);
    $url = get_permalink($post->ID);
    $category = get_the_category($post->ID);
    $cat_name = $category ? esc_html($category[0]->name) : '';
    $cat_url = $category ? get_category_link($category[0]->term_id) : '';
    ?>
<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "BreadcrumbList",
  "itemListElement": [
    {
      "@type": "ListItem",
      "position": 1,
      "name": "ホーム",
      "item": "<?php echo home_url('/'); ?>"
    },
    {
      "@type": "ListItem",
      "position": 2,
      "name": "<?php echo $cat_name; ?>",
      "item": "<?php echo $cat_url; ?>"
    },
    {
      "@type": "ListItem",
      "position": 3,
      "name": "<?php echo esc_html($title); ?>",
      "item": "<?php echo esc_url($url); ?>"
    }
  ]
}
</script>
    <?php
  }
}
add_action('wp_head', 'add_breadcrumb_structured_data');
