位于日本福冈县久留米市的小型网站和网站设计工作室。

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

MEMOMEMO

在 functions.php 中编写实用代码(第 2 部分)

2023-11-14 23:54

/* 启用帖子格式*/
add_theme_support( 'postformats', array(

//you can specify multiple formats in an array.
'aside', //aside
'gallery', //gallery
'image', //image
) );.

/*为管理界面的帖子编辑器应用样式*/
add_editor_style(); // 默认加载 editor-style.css。您也可以指定自己的文件路径作为参数。

//Install a favicon
function custom_favicon() {
echo '<link rel="shortcut icon" 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" sizes="192x192" href="' . esc_url(get_template_directory_uri()) . '/image/android-chrome-192x192.png">' . "n";
echo '<meta name="apple-mobile-web-app-title" content="Your App Title">' . "n";
}
add_action('wp_head', 'custom_favicon');

// 省略绝对路径 //
function edit_menu_link( $atts ) {
if( !is_front_page() ){
$href = $atts['href'];
if( substr($href, 0, 1) === '#') {
$atts['href'] = home_url('/'). $href;
}
}
return $atts;
}
add_filter( 'nav_menu_link_attributes', 'edit_menu_link', 10 );

// 任何标识符、描述 //
function add_register_nav_menu() {
register_nav_menu( 'main-menu', 'main menu' );
}
add_action( 'after_setup_theme', 'add_register_nav_menu' );

<< 返回列表