Wordpress create custom page with php

Categorías: 

Etiquetas: 

Summary

  • Step 1: create page from WordPress admin and note the url slug
  • Step 2: create a file in your active theme named 'page-url-slug.php'
  • Step 3: load WordPress header and footer in the file

Step 1: create page from WordPress admin and note the url slug

  • Just create a simple page from your WordPress installation, wp-admin.php > New Page
  • Call it 'example', the url slug will be that.

Step 2: create a file in your active theme named 'page-url-slug.php'

  • Inside your theme, create a file called 'page-example.php', something like that: wordpress/wp-content/themes/your-active-theme/page-example.php

Step 3: load WordPress header and footer in the file

  • 'page-example.php' content:
<?php get_header(); ?>
 
// Your code goes here
 
// You can use whatever WordPress function, like global objects like $wpdb or user functions
 
<?php get_footer(); ?>