'ffffff',
) );
add_theme_support( 'custom-header', array(
'default-image' => '',
'width' => 1920,
'height' => 400,
'flex-height' => true,
'flex-width' => true,
) );
// HTML5サポート
add_theme_support( 'html5', array(
'search-form', 'comment-form', 'comment-list', 'gallery', 'caption', 'style', 'script',
) );
// カスタムロゴ
add_theme_support( 'custom-logo', array(
'height' => 60, 'width' => 200, 'flex-height' => true, 'flex-width' => true,
) );
// ブロックエディター強化:カラーパレット
add_theme_support( 'editor-color-palette', array(
array( 'name' => __( 'Primary', 'ai-creative-studio' ), 'slug' => 'primary', 'color' => '#1e40af' ),
array( 'name' => __( 'Accent', 'ai-creative-studio' ), 'slug' => 'accent', 'color' => '#f59e0b' ),
array( 'name' => __( 'Success', 'ai-creative-studio' ), 'slug' => 'success', 'color' => '#10b981' ),
array( 'name' => __( 'Warning', 'ai-creative-studio' ), 'slug' => 'warning', 'color' => '#f59e0b' ),
array( 'name' => __( 'Danger', 'ai-creative-studio' ), 'slug' => 'danger', 'color' => '#ef4444' ),
array( 'name' => __( 'Dark Gray', 'ai-creative-studio' ), 'slug' => 'dark-gray', 'color' => '#374151' ),
array( 'name' => __( 'Light Gray', 'ai-creative-studio' ), 'slug' => 'light-gray', 'color' => '#9ca3af' ),
) );
// フォントサイズプリセット
add_theme_support( 'editor-font-sizes', array(
array( 'name' => __( 'Small', 'ai-creative-studio' ), 'size' => 14, 'slug' => 'small' ),
array( 'name' => __( 'Normal', 'ai-creative-studio' ), 'size' => 16, 'slug' => 'normal' ),
array( 'name' => __( 'Medium', 'ai-creative-studio' ), 'size' => 20, 'slug' => 'medium' ),
array( 'name' => __( 'Large', 'ai-creative-studio' ), 'size' => 28, 'slug' => 'large' ),
array( 'name' => __( 'Huge', 'ai-creative-studio' ), 'size' => 36, 'slug' => 'huge' )
) );
// エディタスタイル
add_editor_style( 'style.css' );
// ナビゲーションメニュー
register_nav_menus( array(
'primary' => esc_html__( 'Primary Menu', 'ai-creative-studio' ),
'footer' => esc_html__( 'Footer Menu', 'ai-creative-studio' ),
) );
// カスタム画像サイズ
add_image_size( 'aics-featured', 1200, 675, true );
add_image_size( 'aics-thumbnail', 400, 400, true );
add_image_size( 'aics-hero', 1920, 1080, true );
}
add_action( 'after_setup_theme', 'aics_theme_setup' );
/**
* コンテンツ幅の設定
*/
if ( ! isset( $content_width ) ) {
$content_width = 800;
}
/**
* ウィジェットエリアの登録
*/
function aics_widgets_init() {
// サイドバー
register_sidebar( array(
'name' => esc_html__( 'Sidebar', 'ai-creative-studio' ),
'id' => 'sidebar-1',
'description' => esc_html__( 'Add widgets here to appear in your sidebar.', 'ai-creative-studio' ),
'before_widget' => '',
'before_title' => '
',
) );
// フッターウィジェット(4カラム)
for ( $i = 1; $i <= 4; $i++ ) {
register_sidebar( array(
'name' => sprintf( esc_html__( 'Footer Widget %d', 'ai-creative-studio' ), $i ),
'id' => 'footer-' . $i,
'description' => sprintf( esc_html__( 'Add widgets here to appear in footer column %d.', 'ai-creative-studio' ), $i ),
'before_widget' => '',
'after_widget' => '
',
'before_title' => '',
) );
}
}
add_action( 'widgets_init', 'aics_widgets_init' );
/**
* CSS・JavaScriptの読み込み
*/
function aics_enqueue_scripts() {
// メインスタイルシート
wp_enqueue_style( 'aics-style', get_stylesheet_uri(), array(), AICS_VERSION );
// メインJavaScript
if ( file_exists( AICS_THEME_DIR . '/assets/js/main.js' ) ) {
wp_enqueue_script( 'aics-main', AICS_THEME_URI . '/assets/js/main.js', array(), AICS_VERSION, true );
wp_localize_script( 'aics-main', 'aicsData', array(
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'aics-nonce' ),
'theme' => array( 'name' => 'AI Creative Studio', 'version' => AICS_VERSION ),
) );
}
// スクロールアニメーション
if ( file_exists( AICS_THEME_DIR . '/assets/js/scroll-animations.js' ) ) {
wp_enqueue_script(
'aics-scroll-animations',
AICS_THEME_URI . '/assets/js/scroll-animations.js',
array(),
AICS_VERSION,
true
);
}
// コメント返信スクリプト
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'aics_enqueue_scripts' );
/**
* ブロックエディター用アセット読み込み
*/
function aics_enqueue_block_editor_assets() {
if ( file_exists( AICS_THEME_DIR . '/assets/js/editor-formats.js' ) ) {
wp_enqueue_script(
'aics-inline-formats',
AICS_THEME_URI . '/assets/js/editor-formats.js',
array( 'wp-rich-text', 'wp-element', 'wp-block-editor', 'wp-components' ),
AICS_VERSION,
true
);
}
}
add_action( 'enqueue_block_editor_assets', 'aics_enqueue_block_editor_assets' );
/**
* 抜粋文カスタマイズ
*/
function aics_excerpt_length( $length ) {
return 30;
}
add_filter( 'excerpt_length', 'aics_excerpt_length' );
function aics_excerpt_more( $more ) {
return '...';
}
add_filter( 'excerpt_more', 'aics_excerpt_more' );
/**
* ページネーション
*/
function aics_pagination() {
global $wp_query;
if ( $wp_query->max_num_pages <= 1 ) {
return;
}
$big = 999999999;
$pagination = paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var( 'paged' ) ),
'total' => $wp_query->max_num_pages,
'prev_text' => esc_html__( '« Previous', 'ai-creative-studio' ),
'next_text' => esc_html__( 'Next »', 'ai-creative-studio' ),
'type' => 'list',
) );
if ( $pagination ) {
echo '';
}
}
/**
* ========================================
* SEO最適化機能(公式登録対応版)
* ========================================
*/
/**
* カスタムタイトルタグ生成
*/
function aics_custom_title( $title_parts ) {
$site_name = get_bloginfo( 'name' );
$separator = '|';
if ( is_front_page() && is_home() ) {
$site_description = get_bloginfo( 'description' );
$title_parts['title'] = $site_name;
$title_parts['tagline'] = $site_description;
return $title_parts;
}
if ( is_singular() ) {
$title_parts['title'] = get_the_title() . ' ' . $separator . ' ' . $site_name;
unset( $title_parts['tagline'] );
return $title_parts;
}
return $title_parts;
}
add_filter( 'document_title_parts', 'aics_custom_title' );
/**
* メタディスクリプション自動生成・出力
*/
function aics_meta_description() {
$description = '';
if ( is_singular() ) {
global $post;
// カスタムフィールド優先
$custom_desc = get_post_meta( $post->ID, '_aics_meta_description', true );
if ( ! empty( $custom_desc ) ) {
$description = $custom_desc;
} elseif ( has_excerpt() ) {
$description = get_the_excerpt();
} else {
$content = wp_strip_all_tags( strip_shortcodes( $post->post_content ) );
$description = wp_trim_words( $content, 120 );
}
} elseif ( is_front_page() || is_home() ) {
$description = get_bloginfo( 'description' );
if ( empty( $description ) ) {
$description = 'AIで未来を創造するクリエイティブスタジオ。最先端のAI技術で、あなたのビジネスを次のステージへ。';
}
}
if ( ! empty( $description ) ) {
$description = preg_replace( '/\s+/', ' ', $description );
$description = trim( $description );
$description = mb_substr( $description, 0, 160 );
echo '' . "\n";
}
}
add_action( 'wp_head', 'aics_meta_description', 1 );
/**
* noindex出力
*/
function aics_noindex_output() {
if ( is_singular() ) {
$noindex = get_post_meta( get_the_ID(), '_aics_noindex', true );
if ( '1' === $noindex ) {
echo '' . "\n";
}
}
}
add_action( 'wp_head', 'aics_noindex_output', 2 );
/**
* 画像最適化(公式対応版)
*/
function aics_add_lazy_loading( $content ) {
if ( strpos( $content, 'loading=' ) !== false ) {
return $content;
}
$content = preg_replace( '/
]*loading=)[^>]*)>/i', '
', $content );
return $content;
}
//add_filter( 'the_content', 'aics_add_lazy_loading' );
//add_filter( 'post_thumbnail_html', 'aics_add_lazy_loading' );
/**
* DNS Prefetch設定(最小限)
*/
function aics_dns_prefetch() {
echo "\n\n";
echo '' . "\n";
echo '' . "\n";
echo '' . "\n";
}
add_action( 'wp_head', 'aics_dns_prefetch', 0 );
/**
* ========================================
* カスタマイザー設定
* ========================================
*/
/**
* カスタマイザー設定
*/
function aics_customize_register( $wp_customize ) {
// カラー設定セクション
$wp_customize->add_section( 'aics_colors', array(
'title' => __( 'サイトカラー設定', 'ai-creative-studio' ),
'priority' => 30,
) );
// メインカラー
$wp_customize->add_setting( 'aics_primary_color', array(
'default' => '#1e40af',
'sanitize_callback' => 'sanitize_hex_color',
) );
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'aics_primary_color', array(
'label' => __( 'メインカラー', 'ai-creative-studio' ),
'section' => 'aics_colors',
) ) );
// アクセントカラー
$wp_customize->add_setting( 'aics_accent_color', array(
'default' => '#f59e0b',
'sanitize_callback' => 'sanitize_hex_color',
) );
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'aics_accent_color', array(
'label' => __( 'アクセントカラー', 'ai-creative-studio' ),
'section' => 'aics_colors',
) ) );
// コピーライトテキスト
$wp_customize->add_setting( 'aics_copyright_text', array(
'default' => '',
'sanitize_callback' => 'sanitize_text_field',
) );
$wp_customize->add_control( 'aics_copyright_text', array(
'label' => __( 'コピーライトテキスト', 'ai-creative-studio' ),
'section' => 'aics_colors',
'type' => 'text',
) );
// フッター設定セクション
$wp_customize->add_section( 'aics_footer', array(
'title' => __( 'フッター設定', 'ai-creative-studio' ),
'priority' => 85,
) );
$wp_customize->add_setting( 'aics_show_theme_credit', array(
'default' => false,
'sanitize_callback' => 'wp_validate_boolean',
) );
$wp_customize->add_control( 'aics_show_theme_credit', array(
'label' => __( 'テーマクレジットを表示', 'ai-creative-studio' ),
'section' => 'aics_footer',
'type' => 'checkbox',
'description' => __( 'フッターに "Theme by Locany" を表示します。', 'ai-creative-studio' ),
) );
}
add_action( 'customize_register', 'aics_customize_register' );
/**
* カスタマイザーCSS出力
*/
function aics_customizer_css() {
$primary_color = get_theme_mod( 'aics_primary_color', '#1e40af' );
$accent_color = get_theme_mod( 'aics_accent_color', '#f59e0b' );
$custom_css = ":root { --color-primary: {$primary_color}; --color-accent: {$accent_color}; }";
wp_add_inline_style( 'aics-style', $custom_css );
}
add_action( 'wp_enqueue_scripts', 'aics_customizer_css' );
/**
* コピーライトテキスト取得
*/
function aics_get_copyright_text() {
$custom_text = get_theme_mod( 'aics_copyright_text', '' );
return $custom_text ?: '© ' . date_i18n( 'Y' ) . ' ' . get_bloginfo( 'name' ) . '. ' . __( 'All rights reserved.', 'ai-creative-studio' );
}
/**
* ========================================
* ブロックスタイルの登録
* ========================================
*/
/**
* ブロックスタイルの登録(装飾+アニメーション)
*/
function aics_register_custom_block_styles() {
// 段落用装飾スタイル
register_block_style( 'core/paragraph', array(
'name' => 'highlight-yellow',
'label' => __( '黄色マーカー', 'ai-creative-studio' ),
) );
register_block_style( 'core/paragraph', array(
'name' => 'highlight-blue',
'label' => __( '青色マーカー', 'ai-creative-studio' ),
) );
// グループ用装飾スタイル
register_block_style( 'core/group', array(
'name' => 'info-box',
'label' => __( '情報ボックス', 'ai-creative-studio' ),
) );
register_block_style( 'core/group', array(
'name' => 'warning-box',
'label' => __( '注意ボックス', 'ai-creative-studio' ),
) );
// アニメーション対応ブロック一覧
$animation_blocks = array(
'core/paragraph',
'core/heading',
'core/image',
'core/gallery',
'core/list',
'core/quote',
'core/group',
'core/columns',
'core/column',
'core/cover',
'core/media-text',
'core/buttons',
'core/button',
'core/separator',
'core/table',
'core/pullquote',
'core/verse'
);
// アニメーション効果の定義
$animations = array(
'aics-fade-in' => __( 'フェードイン', 'ai-creative-studio' ),
'aics-fade-up' => __( '下からフワッと', 'ai-creative-studio' ),
'aics-fade-down' => __( '上からフワッと', 'ai-creative-studio' ),
'aics-slide-left' => __( '右からスライドイン', 'ai-creative-studio' ),
'aics-slide-right' => __( '左からスライドイン', 'ai-creative-studio' ),
'aics-zoom-in' => __( 'ズームイン', 'ai-creative-studio' ),
'aics-rotate-in' => __( '回転フェードイン', 'ai-creative-studio' ),
'aics-bounce-in' => __( 'バウンスイン', 'ai-creative-studio' )
);
// 各ブロックに全アニメーションを登録
foreach ( $animation_blocks as $block ) {
foreach ( $animations as $name => $label ) {
register_block_style( $block, array(
'name' => $name,
'label' => $label,
) );
}
}
}
add_action( 'init', 'aics_register_custom_block_styles' );
/**
* ========================================
* SEOメタボックス
* ========================================
*/
/**
* 簡易SEOメタボックス(審査対応版)
*/
function aics_add_simple_seo_meta_box() {
add_meta_box(
'aics_simple_seo',
__( 'SEO基本設定', 'ai-creative-studio' ),
'aics_simple_seo_callback',
array( 'post', 'page' ),
'normal',
'default'
);
}
add_action( 'add_meta_boxes', 'aics_add_simple_seo_meta_box' );
function aics_simple_seo_callback( $post ) {
wp_nonce_field( 'aics_save_simple_seo', 'aics_simple_seo_nonce' );
$meta_desc = get_post_meta( $post->ID, '_aics_meta_description', true );
$noindex = get_post_meta( $post->ID, '_aics_noindex', true );
?>
{
element.classList.add('aics-animation-pending');
});
// Intersection Observer非対応ブラウザの場合は即座に表示
if (!('IntersectionObserver' in window)) {
elements.forEach(element => {
element.classList.remove('aics-animation-pending');
element.classList.add('aics-animation-active');
});
return;
}
// スクロール監視の設定
const observerOptions = {
root: null,
rootMargin: '0px 0px -10% 0px', // 画面下10%に来たら発動
threshold: 0.1 // 要素の10%が見えたら発動
};
// 監視コールバック関数
const observerCallback = (entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const element = entry.target;
// アニメーション発動
element.classList.remove('aics-animation-pending');
element.classList.add('aics-animation-active');
console.log('ACS Animation: アニメーション発動', element.className);
// パフォーマンス向上のため監視を停止
observer.unobserve(element);
}
});
};
// Observer作成と監視開始
const observer = new IntersectionObserver(observerCallback, observerOptions);
elements.forEach(element => {
observer.observe(element);
});
});
";
wp_add_inline_script('aics-main', $inline_script);
}, 999);
/**
* エディタ用JavaScript(ファイルが存在しない場合の代替)
*/
add_action('enqueue_block_editor_assets', function() {
// ファイルが存在しない場合はインラインでエディタ機能を追加
if (!file_exists(get_template_directory() . '/assets/js/animation-editor.js')) {
$inline_script = "
(function() {
const { addFilter } = wp.hooks;
const { Fragment } = wp.element;
const { InspectorControls } = wp.blockEditor;
const { PanelBody, SelectControl } = wp.components;
const { createHigherOrderComponent } = wp.compose;
// ブロックスタイル追加
wp.blocks.registerBlockStyle('core/paragraph', {
name: 'aics-fade-in',
label: 'フェードイン'
});
wp.blocks.registerBlockStyle('core/paragraph', {
name: 'aics-fade-up',
label: '下からフワッと'
});
wp.blocks.registerBlockStyle('core/heading', {
name: 'aics-fade-in',
label: 'フェードイン'
});
wp.blocks.registerBlockStyle('core/heading', {
name: 'aics-fade-up',
label: '下からフワッと'
});
wp.blocks.registerBlockStyle('core/group', {
name: 'aics-fade-in',
label: 'フェードイン'
});
wp.blocks.registerBlockStyle('core/group', {
name: 'aics-fade-up',
label: '下からフワッと'
});
wp.blocks.registerBlockStyle('core/columns', {
name: 'aics-fade-in',
label: 'フェードイン'
});
wp.blocks.registerBlockStyle('core/image', {
name: 'aics-zoom-in',
label: 'ズームイン'
});
console.log('ACS Animation: エディタ機能を読み込みました');
})();
";
wp_add_inline_script('wp-blocks', $inline_script);
}
});
/**
* v1.3.0 機能拡張モジュール読み込み
*/
if ( file_exists( get_template_directory() . '/inc/customizer-extended.php' ) ) {
require_once get_template_directory() . '/inc/customizer-extended.php';
}
if ( file_exists( get_template_directory() . '/inc/meta-boxes.php' ) ) {
require_once get_template_directory() . '/inc/meta-boxes.php';
}
if ( file_exists( get_template_directory() . '/inc/widgets-extended.php' ) ) {
require_once get_template_directory() . '/inc/widgets-extended.php';
}
if ( file_exists( get_template_directory() . '/inc/layout-system.php' ) ) {
require_once get_template_directory() . '/inc/layout-system.php';
}
if ( file_exists( get_template_directory() . '/inc/social-share.php' ) ) {
require_once get_template_directory() . '/inc/social-share.php';
}
if ( file_exists( get_template_directory() . '/inc/table-of-contents.php' ) ) {
require_once get_template_directory() . '/inc/table-of-contents.php';
}
if ( file_exists( get_template_directory() . '/inc/block-patterns.php' ) ) {
require_once get_template_directory() . '/inc/block-patterns.php';
}
if ( file_exists( get_template_directory() . '/inc/content-filter-control.php' ) ) {
require_once get_template_directory() . '/inc/content-filter-control.php';
}
if ( file_exists( get_template_directory() . '/inc/admin-settings.php' ) ) {
require_once get_template_directory() . '/inc/admin-settings.php';
}
if ( file_exists( get_template_directory() . '/inc/heading-customizer.php' ) ) {
require_once get_template_directory() . '/inc/heading-customizer.php';
}
/**
* レイアウト用クラスをbody要素に付与
*/
function aics_add_layout_body_class( $classes ) {
if ( is_singular( array( 'post', 'page' ) ) ) {
$post_id = get_queried_object_id();
$post_layout = get_post_meta( $post_id, '_aics_post_layout', true );
$global_layout = get_theme_mod( 'aics_global_layout', 'two-column-right' );
$layout = ! empty( $post_layout ) ? $post_layout : $global_layout;
// body要素にレイアウトクラスを追加
$classes[] = 'layout-' . sanitize_html_class( $layout );
}
return $classes;
}
add_filter( 'body_class', 'aics_add_layout_body_class' );
/**
* 現在のページがLPレイアウトか判定する関数
*
* @return bool
*/
function aics_is_lp_layout() {
if ( ! is_singular( array( 'post', 'page' ) ) ) {
return false;
}
$post_id = get_queried_object_id();
$post_layout = get_post_meta( $post_id, '_aics_post_layout', true );
$global_layout = get_theme_mod( 'aics_global_layout', 'two-column-right' );
$layout = ! empty( $post_layout ) ? $post_layout : $global_layout;
return ( 'lp' === $layout );
}