How To:Embed PHP Code in a Page

php_logo-50×50.pngIf you want to add PHP code to a page in WordPress, for example to add an RSS feed, there are plugins available but it’s very easy to do it without using a plugin. Here’s how!

1. Make a Template File

Open up the index.php file for your theme. This can be found at wp-content/themes/name of your theme. Add the following lines to the very beginning of the file

<?php
/*

Template Name: rss

*/
?>
Change the template name to whatever is suitable for you.
2. Add the PHP code to the template.
Copy the PHP code you want to embed to this file. For my demo page I added the rss code after this line <div id=”dynamic-content”></div>
3. Save the file with a new file name (I called mine rss.php) and upload to the same place as the original index.php file.
4. Make a new page
Make a new page and choose your new template file from the dropdown box in the sidebar ‘Page Template’ If you add content it will go before the PHP code.
5. Publish your new page!
Here’s a demo page I made using a PHP RSS feed from RSS Free Reader

6 Responses to “How To:Embed PHP Code in a Page”


  1. 1 new zealand tourism

    As versatile as Wordpress is eventually everyone wants to do something that requires a little PHP work.

  2. 2 mozilla firefox download

    Nice little tutorial, thank you :razz:

  3. 3 joseph

    thanks for the tutorial

  4. 4 SEO Consultant

    It is easy to insert custom PHP code onto your wordpress blog. However, unless you have intermediate knowledge on PHP scripting, do not try to use the include function. Many blogs and sites have been hacked every year because they did not ensure that their include functions is written properly and this is very common among forums.

  5. 5 syria

    is that code like include code or it just get external code in other way??? thanks for the tutorial

  6. 6 shashindra Kumar Singh

    :cool:

digg this
Subscribe to My Feed AddThis Social Bookmark Button

Leave a Reply