If you want to incorporate D3 on some, but not all, of your pages in WordPress, this seems to be the way:
- Add a custom page template to your theme. It’s pretty straightforward – copy pages.php, then rename it. Give it a name that you’ll recognize when you make a new D3 sample page by adding the following line to the comments at the top of the page: “Template Name: D3 Page Template”. You can put whatever you want after “Template Name”, but this seemed pretty unambiguous to me.
- Edit your new page template to have an element that will hold your D3 example. I created a “graph” element, but you could use a div with a specific id; it doesn’t matter. You probably want to put the element either just before or just after the line with ““.
- Upload your template (perhaps goes without saying).
- Make a new page using the template you uploaded. To add a D3 code snippet to the page, follow the plugin instructions for wrapping your code in “raw” tags. Make sure that your code appends your SVG (or whatever) element that D3 will be working on to the empty element you created in the template.
That’s about it. Seems simple, but took me hours to figure out. Look for more D3 examples to come…