0

I crated a footer.php and a corresponding customFooter.php. It looked great until I added header.php and customHeader.css. Now the 2 custom css files are overlaping. For example: some of the <img> are not aligned properly, due to the alignment of the pther css file. Is it possible to restrict certain css file only to a specific pphp file??

  • 1
    No, it's not. You should use classes to apply CSS only to specific elements and use different classes where you don't want styles to overlap. – Jacob Peattie Nov 22 '17 at 14:06
0

You can define specific stylesheets for specific PHP files.

If you are using a Child Theme, use the functions.php of the Child.

You should use something like:

function my_custom_css() {
wp_register_style( 'stylesheet_name', get_stylesheet_directory_uri() . '/stylesheet.css' );
}
add_action( 'init', 'my_custom_css' );

function my_custom_css_enqueue() {
// only enqueue on product-services page slug
if ( is_page( 'my-page' ) ) {
    wp_enqueue_style( 'stylesheet_name' );
}
}
add_action( 'wp_enqueue_scripts', 'my_custom_css_enqueue' );
0

I use only one css file for my child-theme. As Jacob says I then use classes to differentiate the elements. An example: In footer.php you have img class="myownimgleft" in customfooter.php you use img class="myownimgright"; in your css file you have .myownimgleft {float: left;} and .myownimgright {float: right;}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.