How to properly edit header.php?

Hello. I want to edit my header.php file. Specifically, I want to edit the tag that appears in it, per the suggestion in [this post](<body <?php body_class(); ?>>https://stackoverflow.com/questions/29280643/change-css-for-logged-in-users-wordpress-x-theme). But header.php seems to contain only

<?php x_get_view( 'header', 'base' ); ?>

So how do I make my desired edit?

I should note that:

  • This testing is done on my private dev site, not my live site.
  • This is only a test. The eventual solution will not involve me editing a theme file. I plan to create a custom function with a hook that accomplishes what I want.

Thanks.

Hey there,

Thanks for writing in. To give you a more accurate response, we first would like to know if your using X or Pro. Also, please give us screenshots of the areas you wish to modify so we could lead you in the right direction.

To understand the template system in X, please see https://theme.co/apex/forum/t/customizations-best-practices/205

Here’s our filters and actions list https://theme.co/apex/forum/t/customizations-actions-and-filters-in-x/208

<body <?php body_class(); ?>> could be found in wp-content\themes\x\framework\views\header\base.php. To override it, copy the template file into the same folder structure in your child theme wp-content\themes\x-child\framework\views\header

Thanks.

1 Like

Thanks for the reply.

> we first would like to know if your using X or Pro.

I am using X.

Also, please give us screenshots of the areas you wish to modify so we could lead you in the right direction.

The specific modification I would like to accomplish is the conditional application of CSS. The CSS would modify the main menu only (see attached screenshot), and be applied only to logged in members. These instructions indicate that I can apply such conditional CSS, but only if I first make a modification to my tag in header.php.

As I mentioned earlier, directly editing header.php is only for testing purposes. The final solution will hopefully not involve doing so.

Thanks.

Hi there,

You do not need to override the header.php or base.php files, you can simply add the code below to functions.php of your child theme:

add_action( 'wp_enqueue_scripts', 'enqueue_loggedin_style' );

function enqueue_loggedin_style() {
	 if (is_user_logged_in()) {
        wp_enqueue_style( 'login-style', get_stylesheet_directory_uri().'/login-style.css' );
     }
}

This code enqueues a CSS file inside the root folder of your Child Theme called login-style.css and it checks if the user is logged in before doing so.

Thank you.

Great thanks so much. That worked, and is very helpful. We can consider this resolved.

Great! Glad that we could be of a help :slight_smile: