Many websites offer code you can copy and paste into your website to easily make their site integrate into yours. While convenient, these code snippets often don’t work correctly with WordPress. If you’ve ever wondered why that happens, here’s an explanation and some ideas of what you can do instead.
Ignored code in WordPress
WordPress ignores certain types of code by default for security reasons. This is because things like forms and PHP can be used to transmit data collected from users or execute advanced functions, and WordPress doesn’t want its users to be tricked into installing something on their sites that could cause harm. This doesn’t mean all ignored code is inherently harmful, but because most WordPress users don’t know how to read code, WordPress wants to offer some basic protections for its users since many wouldn’t be able to tell if the code was nefarious.
What code WordPress ignores
WordPress ignores the following types of code:
- All form tags (<
form>, <input>, <submit>tags)
- Embedded frames (
- All PHP
How to enable ignored code
Copying and pasting form tags, iframe tags, or PHP into a post or page won’t work correctly. In many cases, a plugin is needed instead of pasting the code directly into your site.
If the purpose of the form is to have a user contact you, you could use the built-in WordPress form builder to create a form. Click the Add Contact Form button in the editor window to get started. For more options and flexibility with your forms, use a form plugin like Contact Form 7 instead.
If your form serves a different purpose — signing your visitors up for an email list, for example — look for a plugin from that company. MailChimp, Infusionsoft, Aweber, and Constant Contact all offer integrations for WordPress.
If you’re trying to paste in an iframe, several iframe plugins exist for WordPress. Install one of them, follow the directions the plugin provides to create an iframe shortcode, and paste the shortcode where you want the iframe to appear on your website.
Warning: Only use iframe code from a source you trust. Because an iframe embeds a separate page into yours, it could include code that tracks your site’s visitors.
Any other code
If none of the above options will work, you’ll need to create a custom plugin to run your code. Plugins accept code that is otherwise ignored. If you’re PHP-savvy and familiar with the WordPress codebase, create a plugin that executes the code you want to use with a shortcode and place the shortcode where you want it to appear on your site. If you’re not code-savvy or that last sentence is confusing to you, contact us and we can help.