首页 问答 正文

如何在wordpress主题中添加自定义头部和脚部?

注册会员 / 悠然自学 / 2023-06-11/ 浏览 171 次

在WordPress主题中添加自定义头部和脚部,可以通过修改主题的header.php和footer.php文件来实现。

  1. 添加自定义头部

在header.php文件中,可以添加自定义头部的内容,例如添加一个新的导航菜单。

<header class="custom-header">
  <nav class="custom-menu">
    <?php wp_nav_menu( array( 'theme_location' => 'custom-menu' ) ); ?>
  </nav>
</header> 

在functions.php中注册新的导航菜单:

function custom_menu() {
  register_nav_menu( 'custom-menu', __( 'Custom Menu' ) );
}
add_action( 'after_setup_theme', 'custom_menu' ); 
  1. 添加自定义脚部

在footer.php文件中,可以添加自定义脚部的内容,例如添加一些版权信息和社交媒体链接。

<footer class="custom-footer">
  <div class="custom-social-icons">
    <a href="#" target="_blank"><i class="fa fa-facebook"></i></a>
    <a href="#" target="_blank"><i class="fa fa-twitter"></i></a>
    <a href="#" target="_blank"><i class="fa fa-instagram"></i></a>
  </div>
  <p class="custom-copyright">
    Copyright © 2021 - All rights reserved
  </p>
</footer> 

在css中添加样式:

.custom-footer {
  background-color: #F5F5F5;
  padding: 30px;
}

.custom-social-icons {
  margin-bottom: 30px;
}

.custom-social-icons a {
  display: inline-block;
  margin-right: 10px;
  font-size: 18px;
  color: #000;
}

.custom-social-icons a:last-child {
  margin-right: 0;
}

.custom-footer p {
  text-align: center;
  font-size: 16px;
  color: #999;
} 
大家谈论
    我的见解