0

How can I put my own code in a wordpress page?

This happens when I tried to pic1

pic2

1
  • There should be an option to add a "Code" or "HTML" block to the page, but even if you did that you'd be using it wrong. Your theme already outputs the html and head elements, as well as styles. The WordPress post/page editor is not an HTML editor. If you have highly specific requirements, you might need to create your own template or theme. Jan 15, 2019 at 8:41

2 Answers 2

0

you can make wordpress single page template and put your own code and assign this template to your page wordpress templates

6
  • this is the perfect solution because the editor will add header and footer but in the template you can make your own code and assign your template to this page
    – hai_shar
    Jan 15, 2019 at 8:43
  • how can I make a single page template? the option only shows default template
    – fishnchips
    Jan 15, 2019 at 8:46
  • add template file to your themes file and put this header * Template Name: Full Width Page
    – hai_shar
    Jan 15, 2019 at 8:47
  • sorry but I can't still get it
    – fishnchips
    Jan 15, 2019 at 8:55
  • did you make template file in your theme ?
    – hai_shar
    Jan 15, 2019 at 8:57
0

You can do this by using the native page templates feature in Wordpress.

Simply create a new file under your parent/child theme. ex. my-template.php. This file has to start with a PHP comment that defines the template name like this:

<?php
    /* Template Name: My Cool Template */
    echo "My custom page template!";

After you save and upload the file, you'll find the template in editing page under Page Attributes box:

enter image description here

Note that in most cases you just want to add or modify something in the main template and don't want to lose the whole design. In this case I recommend you copy the code of page.php file in your theme to the new template file you created, and just add you modifications to it. If page.php doesn't exist, just use index.php instead.

6
  • how can I create a new file under your parent/child theme?
    – fishnchips
    Jan 15, 2019 at 10:06
  • Using FTP, locate the directory of your installation then go to wp-content/themes and find the directory of your theme. Jan 15, 2019 at 10:09
  • yeah it works. but how can I use my own code to the page?
    – fishnchips
    Jan 15, 2019 at 10:28
  • Of course you can. Just replace the echo line in my code above and keep the comment at the beginning of the file. Jan 15, 2019 at 13:21
  • Update your question with the code you're trying with so we can help you. Did you close the PHP code section with ?> ? Jan 16, 2019 at 7:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.