Adding php page to wordpress

How to add a .php file to WordPress

I have a php file in my server (say www.example.com/up/up.php). If i access that file through the url, my site says no page found. but i want to call that php file using url parameter. I want to call that file to a download file using url access( say www.example.com/up/up.php?f=207). can someone help me how to do this. as usual i searched fr few days for my problem and came here when i totally cornered. my up.php contains the following code

top.location.href='" . $dialog_url . "'"); > else < $token_url="https://graph.facebook.com/oauth/access_token?" . "client_id=" . $app_id . "&client_secret=" . $app_secret . "&redirect_uri=" . urlencode( $post_login_url) . "&code=" . $code; $response = file_get_contents($token_url); $params = null; parse_str($response, $params); $access_token = $params['access_token']; // POST to Graph API endpoint to upload photos $graph_url= "https://graph.facebook.com/" . $album_id . "/photos?" . "url=" . urlencode($photo_url) . "&message=" . urlencode($photo_caption) . "&method=POST" . "&access_token mt24 mb12">
    phppagespage-template
)" data-controller="se-share-sheet" data-se-share-sheet-title="Share a link to this question" data-se-share-sheet-subtitle="" data-se-share-sheet-post-type="question" data-se-share-sheet-social="facebook twitter " data-se-share-sheet-location="1" data-se-share-sheet-license-url="https%3a%2f%2fcreativecommons.org%2flicenses%2fby-sa%2f3.0%2f" data-se-share-sheet-license-name="CC BY-SA 3.0" data-s-popover-placement="bottom-start">Share
)" title="">Improve this question
)">edited Jul 19, 2015 at 4:28
Brad Dalton
6,4902 gold badges31 silver badges39 bronze badges
asked Jan 22, 2012 at 17:43
10
    You should be able to do it, just provide the full path to the file when you call it.
    – Jared
    Jan 22, 2012 at 18:05
    @Jared I gave the full url but it ends up with no page found error. should i add any codes to function.php about this external file??
    – Felix
    Jan 22, 2012 at 18:23
    Well where are you placing the file, in your active theme's folder?
    – Jared
    Jan 22, 2012 at 18:25
    @Jared I placed it in my serever. www.mysite.com/up/up.php
    – Felix
    Jan 22, 2012 at 18:27
    1
    Well I think it would work the same way even if you had the .php extension. I think it may be a conflict with your rewrite rules possibly, because I've never had a problem accessing a PHP file inside WP with the path to the file.
    – Jared
    Jan 22, 2012 at 20:34
|Show 5 more comments

3 Answers 3

Reset to default
5

What you can do is this:

Put up.php in your active theme's folder, and put this line at the top of your up.php file:

Источник

Add PHP page in WordPress

WordPress is one of the best blogging platforms and Phppot also running on this. I am planning to write a lot more on WordPress and this tutorial is the first from that series.

This is the scenario, we have a custom PHP page that we want to integrate with the WordPress blog. Our PHP file which we are going to integrate may not use any of the WordPress APIs.

Step 1: Create WordPress Template Page

We can start with a sample file and copy page.php, rename it on your choice and put it inside the theme folder ../wp-content/themes/mytheme/

This new file should start with the following content and then be followed by the custom PHP content. This is the WordPress template.

Remember to upload this to the theme folder. Now the WordPress template is ready.

Step 2: Create WordPress Page

Click the “Pages” link from the WordPress Dashboard. The template we created can be used to create this new page. We can give the Page name and choose the “Template” from the drop-down from the “Page Attributes” section.

There the PHP page we uploaded will come with the “ MyTemplate ” listed in the drop down.

WordpressPage

Now publish. Here we go, we have created a WordPress PHP page using our custom code. Whenever this page is linked, our custom PHP code will get executed. We can create any number of WordPress pages using this template.

A real-time scenario is we can construct a sitemap page using this WordPress template option.

  • PHP
  • jQuery
  • JavaScript
  • WordPress
    • WordPress Multilingual
    • WordPress Tutorials
      • WordPress Installation
      • How to Create a Minimal WordPress Theme
      • WordPress Child Theme Template
      • How to Create a Child Page in WordPress
      • How to Add Image in WordPress Sidebar
      • How to Create WordPress Custom Page Template
      • How to Create WordPress Widget
      • How to Create Shortcode in WordPress
      • How to Create Custom Taxonomy in WordPress
      • How to Backup WordPress Database
      • The Right Way to Include JavaScript and CSS in WordPress
      • How to Create and Enable WordPress MultiSite Network
      • Set Featured Image for WordPress Post or Page
      • How to Setup Google Analytics on WordPress Website
      • Creating Custom Post Status in WordPress
      • How to Redirect Your WordPress Blog Readers to a Random Post
      • How to Force Logout All Users from WordPress Site
      • How to Limit Login Attempts in WordPress
      • How to Add WordPress Two-Factor Authentication (2FA) using Google Authenticator Plugin
      • Disabling WordPress Search Feature without Plugin
      • How to Create an Image Gallery in WordPress
      • How to Disable WordPress RSS Feeds
      • How to Limit the Archive Menu List in WordPress
      • How to Display the Last Updated Date of Post in WordPress
      • Add PHP page in WordPress
      • How to Get WordPress Categories
      • How to Rename Uncategorized from WordPress Category
      • Displaying WordPress Recent Posts of a Specified Category
      • WordPress Custom Walker
      • How to Add Avatar Defaults in WordPress
      • WordPress Featured Image
      • Adding Custom Field to WordPress Post
      • WordPress XML-RPC Update Services to Ping
      • Insert Ads (Content) in WordPress Post
      • Error Establishing a Database Connection WordPress Fix
      • How to Move HTTP to HTTPS on WordPress
      • How to Display All the WordPress Posts on One Page
      • How to Embed Video from Facebook in WordPress
      • Show Related Posts in WordPress using YARPP Plugin

      I’m currently available for freelance work.

      1. Simple PHP Shopping Cart
      2. Stripe Payment Gateway Integration using PHP
      3. User Registration in PHP with Login: Form with MySQL and Code Download
      4. PHP Contact Form
      5. How to Create Dynamic Stacked Bar, Doughnut and Pie charts in PHP with Chart.js

      “ The whole experience was extremely professional. We agreed on the requirements and scope of work quickly. The price was fair. Vincy promised quick turn-around and delivered on time . ”

      Michael Goldstein, HHG Development Associates LLC, USA

      Источник

      Реализация идеи

      1. Создадим php-файл. Я назвал свой «test.php» и добавил его в корневой каталог с загруженной темой, вот сюда:

      Должно получится следующим образом:

      2. Для использования всех функций WordPress необходимо подключить «wp-load.php», вставляем приведенный ниже код в наш PHP:

      require_once $_SERVER["DOCUMENT_ROOT"]."/wp-load.php";

      3. Для примера добавляю в php-файл функцию получения временной зоны сайта с выводом на странице:

      $timezone = wp_timezone(); echo $timezone->getName();

      В итоге мой файл выглядит следующим образом:

      В принципе, все готово, теперь можно переходить по ссылке ниже:

      https://название_сайта/wp-content/themes/blogshare/test.php

      Но блин, какая длинная ссылка получилась, это ведь не удобно! Давайте сократим ссылку и создадим человекоподобный URL (ЧПУ). Например, чтобы страница открывалась по короткому урл:

      4. Находим в корневой папке WordPress файл «.htaccess», при помощи которого можно задавать различные настройки сервера apache и открываем его редактором.

      5. Добавляем директиву «RewriteRule» после «RewriteBase»:

      RewriteRule ^(test)/$ /wp-content/themes/blogshare/test.php [L]

      6. Переходим в браузере по заданному URL и видим, что страница отображается и функция отображения часовой зоны работает.

      Готово! И никакие плагины не нужны! Естественно существует огромное множество плагинов, чтобы это реализовать, но в них еще нужно разобраться, а можно за несколько шагов, описанных в статье, сделать самому.

      Источник

      Читайте также:  Svg object fit css
Оцените статью