Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Modify plugin <?php get_header?> function without editing core files

Hello!

I'm developing my own theme for an e-learning purpose, and I'm using LearnPress.

The thing is, users need to get a different header when they are logged in. Ok, i've already done this change on the whole theme, but the <?php get_header()?> function on the theme layouts for single, archive, etc are overwriting my changes.

I need to overwrite the function <?php get_header()?> without editing and hardcoding plugin core files, how can I do it?

I just need to say "make that" <?php get_header()?> get this one:

<?php

function logged_users_header() {

if ( is_user_logged_in() ) { get_header('logged'); } else { get_header(); }

}

?>

I've already inserted this snippet on my functions.php: it worked on the theme pages, not on the plugin pages

Somebody could help me?

I'm trying this - it seems to be right, but is not working...

<?php

function logged_users_header() {

if ( is_user_logged_in() && is_page_template( 'archive-course.php' 'content-course.php' 'content-single-course.php' ) ) { get_header('logged'); } else { get_header(); }

}

?>

3 Answers

Ronald Hunter
Ronald Hunter
17,474 Points

maybe the is_page_template function needs , between the parameters.

Hi,

Do you need to server a completely different header or can you just server a different part of the header? For example, menu items, links, images?

I am noticing some missing commas in your last function to.

Craig

Hello guys, thanks for the attention

I need to display a completely different header.php archive.

Where is missing commas? I put this snippet on the PHP check and it did not find errors..

Still trying...!

Thank you again!