Small homepage/website design shop in Kurume City, Fukuoka Prefecture, Japan.

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

MEMOMEMO

Useful code to write in functions.php (Part 2)

2023-11-14 23:54

/* Enable post formats*/
add_theme_support( 'post-formats', array(
  //you can specify multiple formats in array.
  'aside', //aside
  'gallery', //gallery
  'image', //image
) );

/*Styles for post editor in admin panel Apply*/
add_editor_style(); //loads editor-style.css by default. You can also specify your own file path as an argument.

// Favicon installation
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');

//absolute path omission//
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 );

// Any identifier, description//
function add_register_nav_menu() {
register_nav_menu( 'main-menu', 'main menu' );
}
add_ action( 'after_setup_theme', 'add_register_nav_menu' );

<< Back to list