Skip to main content
Commonmark migration
Source Link

That depends on the type of HTML and JS.

###JavaScript

JavaScript

First of all, separate the dynamic parts from the static parts as much as possible. Then load whatever dynamic variables you need at runtime and queue your static scripts in the header (or footer, whatever). But this way, the majority of your JS is separate from your PHP.

###HTML

HTML

This is a matter of building your code cleanly in the PHP. If you have huge chunks of HTML that you're going to re-use, I'd store those as separate variables. Then piecing things together when the shortcode is called is as simple as:

echo $firstblock;
echo $shortcodecontent;
echo $lastblock;

Rather than trying to build it out procedurally, build an object (yes, PHP supports objects) that contains all of your different HTML blocks, then instruct it which ones to use and which data to pass back. This will save you huge amounts of time.

That depends on the type of HTML and JS.

###JavaScript

First of all, separate the dynamic parts from the static parts as much as possible. Then load whatever dynamic variables you need at runtime and queue your static scripts in the header (or footer, whatever). But this way, the majority of your JS is separate from your PHP.

###HTML

This is a matter of building your code cleanly in the PHP. If you have huge chunks of HTML that you're going to re-use, I'd store those as separate variables. Then piecing things together when the shortcode is called is as simple as:

echo $firstblock;
echo $shortcodecontent;
echo $lastblock;

Rather than trying to build it out procedurally, build an object (yes, PHP supports objects) that contains all of your different HTML blocks, then instruct it which ones to use and which data to pass back. This will save you huge amounts of time.

That depends on the type of HTML and JS.

JavaScript

First of all, separate the dynamic parts from the static parts as much as possible. Then load whatever dynamic variables you need at runtime and queue your static scripts in the header (or footer, whatever). But this way, the majority of your JS is separate from your PHP.

HTML

This is a matter of building your code cleanly in the PHP. If you have huge chunks of HTML that you're going to re-use, I'd store those as separate variables. Then piecing things together when the shortcode is called is as simple as:

echo $firstblock;
echo $shortcodecontent;
echo $lastblock;

Rather than trying to build it out procedurally, build an object (yes, PHP supports objects) that contains all of your different HTML blocks, then instruct it which ones to use and which data to pass back. This will save you huge amounts of time.

Source Link
EAMann
  • 32.2k
  • 9
  • 88
  • 147

That depends on the type of HTML and JS.

###JavaScript

First of all, separate the dynamic parts from the static parts as much as possible. Then load whatever dynamic variables you need at runtime and queue your static scripts in the header (or footer, whatever). But this way, the majority of your JS is separate from your PHP.

###HTML

This is a matter of building your code cleanly in the PHP. If you have huge chunks of HTML that you're going to re-use, I'd store those as separate variables. Then piecing things together when the shortcode is called is as simple as:

echo $firstblock;
echo $shortcodecontent;
echo $lastblock;

Rather than trying to build it out procedurally, build an object (yes, PHP supports objects) that contains all of your different HTML blocks, then instruct it which ones to use and which data to pass back. This will save you huge amounts of time.