• Hi, everyone. I just started understanding and using a child theme. I understand that using a child theme will secure my theme from experiencing any alterations from updates.

    I am trying to understand how to edit .php files using a child theme. I am trying to remove the line of code in the Header.php which calls the search bar. Please let me know if this is the right way to edit a .php file.

    I created a new Header.php file in my child theme, and I copied the line of code from the parent theme’s Header.php, and pasted it in my child theme’s Header.php. After saving, my page looked as if all the code had been removed from it, there was virtually nothing on it.

    I then took all the code from the parent’s Header.php, and pasted it into the child’s Header.php, and commented out the search bar code, and after saving the search bar was gone and everything on the page looked the way it should be.

    But what I don’t understand is, what happens now if an update does in fact happen? Will the update have no effect on the various .php files I choose to customize? Also, what is the point of using a child theme specifically for .php files if the whole page of the parent’s .php file needs to be copied over to function properly, if any update won’t take effect on the child?

    I hope I explained this well enough 🙂

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Will the update have no effect on the various .php files I choose to customize?

    I cannot say with absolute certainty, but logic says it would not. A change in the WordPress core might cause trouble for a given plugin inside a certain Theme or something like that, but the Parent Theme must always-and-only do what the Child Theme does not do.

    Also, what is the point of using a child theme specifically for .php files if the whole page of the parent’s .php file needs to be copied over to function properly, if any update won’t take effect on the child?

    i think the point there is that we can now modify away and the original file in the Parent Theme will still be there if we might ever decide or need to turn that particular duty back to the Parent. And like in the case of a header file, for example, it would be inefficient to get part of that info from the Child Theme and then have to go get the remainder elsewhere and then assemble it all once again every time someone refreshes a browser.

    Thread Starter Sanphorii

    (@sanphorii)

    Thank you Lee, for your response, I’m still trying to understand how child themes work, so thank you for replying.

    I’m also wondering about conditionals and changing functions, but that might be a question about WordPress in general. For example, I was wondering if there was a way to remove the navigation bar from the Home page only, then have it reappear on every other page.

    From what I understand about this, I should add a php conditional such as an if statement to check if the front page is currently being viewed and if it is, to hide the navigation bar, and if it’s not, then show the navigation bar.

    I’ve read something about using a WordPress ‘hook’ or something like that…I’m not quite familiar with modifying template files.

    Does anyone know the code I should use to get the navigation bar to disappear on the main page, and reappear on any other pages, and how I can implement that?

    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘How To Edit ,php Files Using A Child Theme’ is closed to new replies.