位於日本福岡縣久留米市的小型網站與網站設計工作室。

猫壱屋 サイト ホームページ 作成 制作

MEMOMEMO

在functions.php中編寫的有用程式碼(第2部分)

2023-11-14 23:54

/* 啟用貼文格式 */
add_theme_support( '後格式', array(
//一個陣列中可以指定多種格式。
'aside', //aside 'gallery', //畫廊 'image', //圖片
) );

/*在管理畫面上套用貼文編輯器的樣式*/
add_editor_style(); //預設載入editor-style.css。您也可以指定您自己的檔案路徑作為參數。

//設定圖示
函數custom_favicon() {
echo '<link rel="快速圖示" type="image/x-icon" href="' .esc_url(get_template_directory_uri()) . '/image/favicon.ico" />' . "n";
echo '<link rel="apple-touch-icon" Sizes="180x180" href="' .esc_url(get_template_directory_uri()) . '/image/apple-touch-icon.png">' . "n";
echo '<link rel="icon" type="image/png" size="192x192" href="' .esc_url(get_template_directory_uri()) . '/image/android-chrome-192x192.png">' . "n ”;
echo '<meta name="apple-mobile-web-app-title" content="您的應用程式標題">' . "n";
}
add_action('wp_head', 'custom_favicon');

//省略絕對路徑//
函數 edit_menu_link( $atts ) {
if( !is_front_page() ){
$href = $atts['href'];
if( substr($href, 0, 1) === '#' ) {
$atts['href'] = home_url('/').$href;
}
}
返回$atts;
}
add_filter( 'nav_menu_link_attributes', 'edit_menu_link', 10 );

// 任意標識符、描述 //
函式 add_register_nav_menu() {
register_nav_menu( '主選單', '主選單' );
}
add_action( 'after_setup_theme', 'add_register_nav_menu' );

<< 返回列表