I'm learning how to make a WordPress theme from scratch & I'm facing a bad problem right now. The problem is that the CSS styles that I've added does not apply to the menu navigation of my theme.
Here's the index.php
file:
<?php
get_header();
if (have_posts()):
while (have_posts()) : the_post(); ?>
<article class="post">
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<h2><?php the_content(); ?></h2>
</article>
<?php endwhile;
else:
echo '<p>No content found!</p>';
endif;
get_footer();
?>
Here's the header.php
file:
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo('charset'); ?>">
<meta name="viewport" content="width=device-width">
<title><?php bloginfo('name'); ?></title>
<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<div class="container">
<header class="site-header">
<h1><a href="<?php echo home_url(); ?>"><?php bloginfo('name'); ?></a></h1>
<h5><?php bloginfo('description'); ?></h5>
<nav class="site-nav">
<?php
$args = array(
'theme_location' => 'primary'
);
?>
<?php wp_nav_menu($args); ?>
</nav>
</header>
As you can see I added the css class site-nav to the tag and then I coded this as css styles to it:
.site-nav ul{
margin:0;
padding:0;
}
.site-nav ul:before, .site-nav ul:after{content: "";display:table;}
.site-nav ul:after{clear:both;}
.site-nav ul{*zoom:1;}
.site-nav ul li{
list-style:none;
float:left;
}
But whenever I run the theme, I get this screen:
But note that I already have the functions.php
which adds the CSS styles and I have added other CSS styles such as body or etc to it and it works but I don't why the menu navigation does not change !!
Here's the functions.php
:
<?php
function learningWordpress_resources(){
wp_enqueue_style('style', get_stylesheet_uri());
}
add_action('wp_enqueue_scripts','learningWordpress_resources');
register_nav_menus(array(
'primary' => __('Primary Menu'),
'footer' => __('Footer Menu'),
));
?>
Here's the full CSS code
You have to provide class
Goto check Css like this
functions.php changes
Refer: http://www.wpbeginner.com/wp-themes/how-to-style-wordpress-navigation-menus/