0

When I’m interested in CSS/HTML/JS of some element on the site, I preview it and test modifications in the browser devtools. It is clear to me here. And how is it in PHP? I have a page placed on WordPress and I’m interested in some element. I would like to find out where is the PHP code that generated this element. Then I’d like to modify this code and view the changes. What’s the smartest way to do that?

I know I need files in Design -> Theme editor. I also use child theme. I implemented some JS scripts in functions.php. Now I’m interested in e.g. element containing information about the author in main collection and single post. Or another issue: in editing the post we have the “author” field. As an alternative I’d like to add another field called “added by” (many of my posts are only links with short description, so it’s hard to talk about authorship here). I understand that I’m entering the WordPress Development area. I have no complete idea how to start. Courses, manuals, documentation? How should I start exactly? What should the working environment consist of?

4
  • 1
    good place to start is to research theme templates and how to edit them. they are written in PHP and most HTML markup is generated by them.
    – majick
    Mar 12, 2020 at 10:46
  • Thanks for the answer. But how to research them? What tools to use? Should I run a theme for example in XAMPP and modify the code in an editor? I use VSC. Are there any plugins for this that make it easier to analyze the code? I don't want my work to look like looking for a needle in a haystack.
    – reti
    Mar 12, 2020 at 11:28
  • 1
    understand the "wordpress template hierarchy" to find the naming of templates, but if you want to find a specific element from the inspect or page source, have a copy of the theme locally and use a tool to "Find in Files" the ID or class keyword you want and modify the template from there.
    – majick
    Mar 12, 2020 at 13:37
  • Thanks for the answer. That's exactly what I did. I've moved my website to XAMPP and I'm looking for key words with Agent Ransack. Additionally, I compare the found files with the list generated by Show Current Template plugin and investigate only those files that are on the list.
    – reti
    Mar 13, 2020 at 20:44

1 Answer 1

1

You can ask a dozen developers how they work with themes or plugins and you'll get a dozen different answers.

My method is to use NetBeans to edit php files stored locally on my computer and then ftp (NetBeans upload) them to a test server with wp_debug turned on. NetBeans turns the theme or plugin files into projects and from there you can search all files in a project. I also use a maintenance mode plugin on the testing site so that if anyone visits the site they don't see me monkeying around with code or errors. Yes, I could do this with a LAMP stack on a machine on my network but to me, that's a pain to maintain and get set up. For $5 a month I can get hosting with any version of PHP and MYSQL with PHP MyAdmin to make database changes.

As for documentation and training, that depends on your knowledge of PHP. If you know PHP well enough then the only thing you need to worry about is WP specific syntax. If you see something in the code you don't understand, use your Google IT department.

https://developer.wordpress.org/

That's your bible. Every function, hook, class or method used in WordPress is there with the complete code and usually, some examples.

Good luck.

1
  • Thank you very much for your answer. For now I'm crawling in PHP and I think for the beginning local hosting on XAMPP + Visual Studio Code + Agent Ransack (search for words in files) + Show Current Template WP plugin should be enough. I still have to read about this wp_debug.
    – reti
    Mar 13, 2020 at 21:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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