My question is: Is it ok, or even preferable, to use html instead of php when possible?

Why I ask:
Wordpress seems to use php even for simple tasks, where old good html would do the job. Php code is not famous for its simplicity or readability. Besides this, I guess that all the unnecessary database requests make the serving of the web pages just a bit slower. So I wonder if there is a good reason, I can not think of, that WP prefers to use php instead of html.
Example:

<div class="site-info">
<?php do_action( 'twentyfourteen_credits' ); ?>
  <a href="https://wordpress.stackexchange.com/questions/201968/<?php echo esc_url( __("http://wordpress.org/', 'twentyfourteen' ) ); ?>"><?php printf( __( 'Proudly powered by %s', 'twentyfourteen' ), 'WordPress' ); ?></a>.
 Copyright ©<?php echo date( 'Y' ); ?>
</div>

instead of

<div class="site-info">
 <a href="http://wordpress.org">Proudly powered by WordPress</a>.
 Copyright ©2015
</div>

(I understand that in the example above, I have to change the year number once per year, and the text can’t be translated, but this is IMO an acceptable trade off for nicer, faster code)

4 Answers
4

Quite strange that the core developers would decide to make an URL translatable, it is actually a case here of over-doing something. But anyways, lets get to the main question

PHP vs HTML

Although there are many reasons I can think of why one would prefer PHP above HTML, and that goes for the core developers as well, the main reason lies in one big difference between these two different languages

  • PHP is dynamic language and HTML is static language

This means that code written in PHP will update itself according to the condition/s set for that specific operation, it does not need human intervention, while anything written in HTML will remain the same until someone manually updates the code to reflect changes, so it requires human intervention. Not having to manually update a single line of code or a thousand lines of code when changes are required is one of the main reasons PHP is used and prefered above a language like HTML

I do think your main issue is that you are still very new to PHP and do not really understand the language as such, which is actually a great opportunity then to dig in PHP and to learn the basics to get you going

As to your exact question, there is nothing wrong swopping PHP with HTML, but you will loose the dynamic aspect of PHP

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *