The main differences are: the first snippet has html inside php while the second one has php inside html. Both approaches are basically valid, both are fine.
I would however always prefer (and recommend) to have php inside html because chances are that a third person / designer might have less difficulties in understanding the code and i.m.h.o. it is less likely to mess with it.
Related Posts:
- How do I change/modify the_post_thumbnail(); html output?
- Why would a GET variable one one page of a site cause a 404 error when a GET variable works on another page of a site?
- Where should I install a PHP library into WordPress so that code in a webpage can activate it?
- Correct way to make static pages editable in wordpress
- Nice scroll to wordpress
- Multiple pages on one with different HTML
- Is it ok to replace php code with html?
- Add custom HTML to posts page
- Minify HTML, CSS, JS with PHPWee?
- Header has extra HTML block at top before my code
- Blank space at beginning of tag?
- Add HTML Attributes To Anchor Tags In `wp_list_categories()` Function
- Correct syntax to html php conversion
- How to properly insert a link to a template in WordPress?
- Show post in slider
- How can I hide Home in my menu in a specific page?
- Getting a specific post values to another div or modal
- Add a class to the anchor tag on HTML5 gallery
- how to remove metadata from the posts of my blog?
- How to store data from multiple forms using ajax and php
- search and replace preword from author
- WP grandchild categories in nested ul li
- Use DOMDocument with ob_start breaks my HTML code
- selected option if current category is the value
- Settings API callback function inserts html quotes from nowhere
- How create a Shortcode with hover and complex options
- How do I remove the product thumbnail link from a specific div in Woocommerce? [closed]
- WordPress Multiple Navigation bars
- Login to wordpress by clicking a link and specifying usernaname and password in url
- Auto 301 to full post permalink? (using : /archive/%post_id% to %post_name% )
- How do I add a custom css to all posts without affecting homepage css? [closed]
- Noscript not working as it should in wordpress site
- Wrapping a Sidebar within
- Add Codepen animation as Preloader to WordPress
- HTML escaping data with ajax requests
- Add data-id attribute to child page links
- HTML table attributes ignored
- How to edit HTML of my website on WordPress? [closed]
- WordPress wp-admin redirect and exception
- How to rename woocommerce-billing-fields
- Prevent redirect to wp-login.php
- How to add post meta in while loop?
- Adding function to child theme’s function.php
- How to use the checked() function to check for a non-empty var
- Calling function in loop causes repeat data
- Find out last 7 days of upload images, last week uploaded image from Gallery and display them in different pages
- Link to page with posts of specific type
- Custom forms with HTML
- Wrap title and excerpt in a div (latest posts block)
- Displaying images outside the content
- how to changes mobile menu toggle breakpoint in WordPress
- PHP inside echo HTML
- WordPress User Meta value variable into Google Gauge Chart
- population category dropdown and sub category onselect
- PHP function for horizontal Woocommerce thumbnails and badges
- What are the advantages/disadvantages of ways to use php template files?
- Using Google Analytics in an enqueued JS file
- dynamic php menu with hidden sub-categories only showing when the category name is clicked
- couldnt show short code atts in category
- Add Link to PHP message
- separate list of programs in html/javascript coming from php
- Remove span tags from WooCommerce Downloads page
- Drop down question
- How to enable HTML tags in category description without breaking the category page
- How do I disable cache for a certain page?
- Can’t display anything through homepage text editor
- How can I edit the final HTML structure of the whole web page
- Woocommerce custom attributes list help
- WooCommerce multiple custom fields code
- How to override html codes in wordpress?
- Access certain Entry in HTML-Table and pass the entry-data in WP not working [closed]
- Allowing HTML elements in title widgets spacing problem
- Target a specific container to style on WordPress storefront theme
- How to include different html tags in the header for different pages?
- Create html tree sitemap
- Pass form attributes to another php template in wordpress
- Custom HTML form using PHP – help with ajax/username validation
- Code works on page-example.php by not category-example.php
- How to create a php page to collect information from a html page
- Font-Family does not looks like how it should be [closed]
- Can’t make product images clickable
- I need help implement a Javascript code into the PHP file
- WooCommerce – Print Processing orders [closed]
- Category – “No content found”
- Add options to WordPress backend
- Automatically create a loop for post ID
- WordPress – Image href for home menu nav not working
- What is the best way to get the first few post from WordPress in different divs using a loop?
- How to style this wp_list_pages markup
- How To: Simple domPDF Example
- Cant get theme to change footer color through theme customizer
- Save Option on Database
- Parse error: syntax error, unexpected ‘}’ in
- Sorting Problem
- Custom HTML/CSS Theme into WordPress – SEO considerations
- How to enqueue structured data as file – jsonld file seems not to work
- ‘This Field is Required.’ is Not Displaying on CF7 [closed]
- Slick slider not working on wordpress
- How to modify default tags in wp_head()
- #038 & wordpress Help