Sarathlal N

Add custom PHP code in Magento 1 CMS page

In Magento, we can’t directly add our custom PHP code in CMS page. But we have an option to call our template files as blocks in CMS page.

So if we want to use custom PHP code in Magento CMS page,

  1. first make a new template file (.phtml file) with our custom PHP code inside template folder.
  2. Then call it as a block in CMS page like below code snippet.

    {{block type="core/template" template="page/myfile.phtml"}}
    

We can put our file in any where inside template or we can make new folder for this custom files. But when call as block, point to correct file path.

I made my new file inside page folder in template. So when call block, I point to my file inside page folder like page/myfile.phtml as template.

Looking for a skilled WordPress/WooCommerce developer? I'm currently available for freelance, contract, or full-time remote opportunities! Let's create something amazing together. Send me a quick message, and I'll respond within 24 hours!

Recent Posts

  1. Automating Code Linting with GitHub Actions for WordPress Plugins
  2. Comprehensive Guide to Linting PHP, JavaScript, and CSS in WordPress Plugins Using Composer
  3. The Ultimate Guide to Indexing in Database Design
  4. Understanding 'update_meta_cache' in WordPress - When to Use It, When Not to, and Its Impact on Database Queries
  5. A Guide to Configuring JavaScript and SCSS Paths in WordPress Plugins with @wordpress/scripts

Your Questions / Comments

If you found this article interesting, found errors, or just want to discuss about it, please get in touch.