How to Add Custom Code and Shortcodes in Blocksy: A Troubleshooting Guide
Content
Adding custom HTML, JavaScript, or shortcodes is a common way to extend a WordPress site's functionality. However, integrating this code with the Blocksy theme can sometimes be confusing, leading to issues where the code doesn't execute and instead displays as plain text. This guide explains why this happens and walks through the most effective solutions.
Why Your Custom Code Might Not Be Working
Based on community reports, the primary reasons code fails to execute are:
- Incorrect Placement: Certain areas of a WordPress site, like archive pages or some header elements, are not directly editable through the standard page editor.
- Theme Updates: Manually editing theme files (e.g., header.php) is not recommended, as your changes will be erased every time the theme updates.
- WordPress Security: For security reasons, WordPress does not allow the execution of raw PHP code within posts, pages, or many theme options.
- Plugin Conflicts: Sometimes, a shortcode from a specific plugin may not be compatible with the way Blocksy outputs content in certain areas.
Common Solutions for Adding Custom Code
1. Using the Header HTML Element for Shortcodes
To insert a shortcode into your header, use the built-in HTML element in the Blocksy header builder.
- Go to Customize → Header → Header Builder.
- Add an HTML element to your desired header row.
- In the element's settings, paste your shortcode (e.g.,
[my_shortcode]). - Important: Switch from the 'Visual' tab to the 'Text' tab before pasting to ensure the shortcode is not altered.
- Publish your changes. You may need to refresh the page to see the shortcode take effect.
Note: This method supports shortcodes but will not execute PHP code.
2. Using a Dedicated Plugin for Advanced Code Snippets
For adding PHP code, global JavaScript, or CSS, the safest and most update-proof method is to use a dedicated snippet management plugin like Code Snippets or WPCode. These plugins allow you to safely add code that persists through theme updates without modifying core theme files.
3. Official Plugins for Third-Party Services
For integrating code from services like Google AdSense or Analytics, it is highly recommended to use the official plugin provided by the service (e.g., Google's Site Kit plugin). This ensures proper integration and avoids code being stripped during updates.
What Doesn't Work (And What to Do Instead)
- Editing Theme Files: Avoid directly editing theme files like
header.phporfunctions.phpin a parent theme. Your changes will be lost on update. Use a child theme if you must edit files. - PHP in Posts/Header: You cannot directly insert PHP code into the header HTML element or a post. Use a snippet plugin to add PHP functionality.
- Certain Plugin Shortcodes: If a plugin's shortcode does not work within the HTML element, try a different insertion method or contact the plugin's support for compatibility advice.
Troubleshooting Checklist
- Is it a shortcode? → Use the Header HTML element and paste it in the 'Text' tab.
- Is it JavaScript? → Use a dedicated snippet plugin or a widget area with a 'Custom HTML' widget.
- Is it PHP? → Use a snippet plugin. Never paste it directly into the theme customizer.
- Is it for a service like Google AdSense? → Use the service's official WordPress plugin.
- Did you refresh? → The Customizer preview may require a full page refresh to render the shortcode correctly.
By following these methods, you can reliably add custom functionality to your Blocksy-powered site without fearing lost code after the next update.
Related Support Threads Support
-
Any difference between CodeSnippets and …https://wordpress.org/support/topic/any-difference-between-codesnippets-and/
-
How to add intro text between the top row and blog posts?https://wordpress.org/support/topic/how-to-add-intro-text-between-the-top-row-and-blog-posts/
-
How to add simple inline Javascript code to Widget in Footerhttps://wordpress.org/support/topic/how-to-add-simple-inline-javascript-code-to-widget-in-footer/
-
Is there any way to add a class to .entry-content?https://wordpress.org/support/topic/is-there-any-way-to-add-a-class-to-entry-content/
-
How insert code snippet html (CTA) between header and content?https://wordpress.org/support/topic/how-insert-code-snippet-html-cta-between-header-and-content/
-
How to add a link to my Logo in the header.https://wordpress.org/support/topic/how-to-add-a-link-to-my-logo-in-the-header/
-
why my HTML code in header does not work?https://wordpress.org/support/topic/why-my-html-code-in-header-does-not-work/
-
Introduce OG code directly on Blocksy?https://wordpress.org/support/topic/introduce-og-code-directly-on-blocks/
-
Newsletter Subscribe Extensionshttps://wordpress.org/support/topic/newsletter-subscribe-extensions/
-
short codeshttps://wordpress.org/support/topic/short-codes-64/
-
How to add nofollow noindex on the comment form?https://wordpress.org/support/topic/how-to-add-nofollow-noindex-on-the-comment-form/
-
Why Amazon ads not showing?https://wordpress.org/support/topic/why-amazon-ads-not-showing/
-
How to add adsense tag in blocksy news child theme?https://wordpress.org/support/topic/how-to-add-adsense-tag-in-blocksy-news-child-theme/
-
Html element on Header not workhttps://wordpress.org/support/topic/html-element-on-header-not-work/
-
It removes Google Adsense Code everytime there is an update.https://wordpress.org/support/topic/it-removes-google-adsense-code-everytime-there-is-an-update/
-
Downloading Block Content codeshttps://wordpress.org/support/topic/downloading-block-content-codes/
-
Insert shortcode directly in header?https://wordpress.org/support/topic/insert-shortcode-directly-in-header/
-
Inserting the header search as a blockhttps://wordpress.org/support/topic/inserting-the-header-search-as-a-block/
-
How to add Ajax search window on the hero headerhttps://wordpress.org/support/topic/how-to-add-ajax-search-window-on-the-hero-header/
-
How to add addtional elements in header ?https://wordpress.org/support/topic/how-to-add-addtional-elements-in-header/
-
Insert text before featured imagehttps://wordpress.org/support/topic/insert-text-before-featured-image/
-
How to add a shortcode to a page when editing with Blocksy.https://wordpress.org/support/topic/how-to-add-a-shortcode-to-a-page-when-editing-with-blocksy/
-
shortcode support in headerhttps://wordpress.org/support/topic/shortcode-support-in-header/
-
Code footerhttps://wordpress.org/support/topic/code-footer/
-
Blocksy Shortcode Quaeryhttps://wordpress.org/support/topic/blocksy-shortcode-quaery/
-
How to add search box on a page or post using shortcode?https://wordpress.org/support/topic/how-to-add-search-box-on-a-page-or-post-using-shortcode/
-
Is there a shortcode to display social share buttons?https://wordpress.org/support/topic/is-there-a-shortcode-to-display-social-share-buttons/