Press "Enter" to skip to content

Integrating WordPress into PHP Scripts


Today, I had to use the custom PHP script I just created in a new WordPress application. I did not develop a WordPress plugin to handle this existing code, but instead used WordPress directly in my script.

If you have a lot of custom PHP code, using WordPress in your script is a good choice.

When you get a large amount of PHP codebase from previous development work. There are usually other libraries in your code, such as Symfony, Zend Framework, Pear, etc. You don't want to split them. You have work code and you want it to stay together.

For me, I created a data collection form for the client. But this is not the general form. It has more than 100 form variables. They consist of text input, radio boxes, check boxes and textarea. I want to use this form directly in my WordPress application. In addition, I hope that integration is easy.

The solution is actually very simple.

Existing PHP Code

For example, suppose this is my existing PHP code (this is a simple script to illustrate this).

</p> <form name = datacollection method = post action = index.php> &lt;input type = text name = first_name value = &quot;<php ​​echo $ _POST [&#39;first_name&#39;];?>&quot;&gt; <input type = submit value = "Submit Data "> </ form>

But the problem is that this is just a form of data collection. How does the existing website look and feel? How can I make the above code look like the same template layout for my WordPress application.

For example, one solution is to add raw HTML. But this is both time consuming and not dynamic. If the WordPress template changes, I must manually change it here. Not what I want to do.

<head> <title> My PHP form page </ head> <body> </p><!-- adman_adcode (middle, 1) --> <!-- Begin BidVertiser code --> <SCRIPT data-cfasync="false" SRC="//" TYPE="text/javascript"></SCRIPT> <!-- End BidVertiser code --> <!-- /adman_adcode (middle) --> <form name = datacollection method = post action = index.php> &lt;input type = text name = first_name value = &quot;<php ​​echo $ _POST [&#39;first_name &#39;];>&gt;&quot;&gt; <input type = submit value =" Submit Data "> </ form> </ body> </ html>

However, this is not entirely correct. I will have to match the navigation, including the stylesheet, and make sure the HTML exactly matches the look and feel of my main site.

Better solution

Instantiated WordPress and used functions built into the code.

<php / include the WordPress loader file $ root = "$ _ SERVER [&#39;DOCUMENT_ROOT&#39;];" require ($ root. &#39;/wp-load.php&#39;); // call the WordPress header function get_header (); > <form name = datacollection method = post action = index.php> &lt;input type = text name = first_name value = &quot;<php ​​echo $ _POST [&#39;first_name&#39;];?>&quot;&gt; <input type = submit value = " Submit Data "> </ form> <php // include the footer get_footer (); ?>

Do you know how easy this is? WordPress is instantiated on my page. Then I instruct the page to call the WordPress header and footer functions.

The header and footer function provides everything I need for my WordPress website template. It automatically fills in HTML, CSS and any Javascript, and closes all open tabs at the bottom.


Let PHP do the job. When you can automatically generate WordPress code through WordPress, you don't need to copy WordPress code in plain HTML.

The added benefit is that if the main WordPress site layout changes, the template that packages the custom PHP code will immediately reflect these changes.

Business Credit: No Personal Credit And No Personal Guarantee Our Business Credit Membership Provides Weekly Training,resources,vendor Credit Lines, Cash Credit Sources And Banking Contacts. Brand New High Converting Self Help/wealth Generation Success Package. How To Buy Commercial Real Estate With No Cash And No Credit! Birddogbot - Real Estate Deal-finding Solution For Investors (view mobile)! Fan Victor - The Ultimate Fantasy Sports Plug-in (view mobile)! Get Lifetime Commission Per Customer! Our $1 Trial + Live Support Is Converting Like Crazy! Learn To Speak The Hebrew That Really Matters Using Sound, Video And Text. Recurring Charge! Legit Writing Jobs (view mobile)! Modern Love - Dating And Relationship / Get Your Ex Back (view mobile)! Next Generation Backlink Indexer. Own The Software That Takes Backlink Indexing To The Next Level With Our Brute Force Technology! Maitrisez Votre Acne Natural Treatment For Acne- Acne Treatment French Version. (view mobile) Membership Site For Learning Spray Paint Art. There Is A Thriving Community Of Street And Spray Paint Artists Online And In The World! Diy Car Painting Auto Body Course - Great For Automotive Male Traffic (view mobile) Astonishing Conversions On This New Online Dating For Women Program From Digital Romance. A Service That Every Homeowner Desperately Can Use: A Property Tax Assessment Review Service. Roofing Business Blueprint Uses The Latest Software & Marketing Tools Developed By Roofing Sales Training Expert David Deschaine! Discover How You Can Build A Complete Business Or Corporate Credit Profile In 90 Days! The Big Diabetes Lie - Real Dr Approved Diabetes Offer (view mobile) This Is An 11 Hour Video Course Teaching Guys How To Pick Up/date Women By Improving Their Communication Skills With Women! It's Never Been This Easy To Make Money Promoting Registry Cleaners! Instabuilder 2.0 - The Ultimate WordPress Marketing Plugin (view mobile)! Internet Jetset - Join The Internets Elite Group Of Middlemen (view mobile)! "#1 Stock Investing Club", Wealth Builders Club,monthly Commissions (view mobile)! Join The Live Stream Event From Anywhere On Any Device! Killer Conversions With 1 Click Recurring Billing Upsells For Max Earnings. The Millionaire Society Provides The Highest Quality Make Money Products Available! Lowest Refunds In The Market Because Customers Love This Product! Long Term Money Maker! Just Ask! Promote This, It Makes You Money! Put This Beast To Work For You On Lists Or Cold Traffic And Just Watch The Dollars Pile Up. New - Recurring Billing Front End! Huge Conversions (5%+ In Tests). 101 Toxic Food Ingredients - New Conversion Breakthrough! For Problem Drinkers. Enjoy A Strong Conversion Rate! Radical Inner Game - The Ultimate Seduction Product! hese Fun And Exciting Games Will Shoot Your Retention Rates Through The Roof! The Oxidized Cholesterol Strategy - Blue Heron Health News (view mobile)! Personal Trainers, Weightroom Instructors And Group Fitness Instructors Looking To Get Better Results With Injuries, Fitness Plateaus And Preventing Injuries! Self-esteem Elevation For Children Coaching Certification! Family Friendly Fat Burning Meals! A Lifetime Of Homework (view mobile)! Tacfit 26: New Generation. The Tactical Fitness Personal Gym System. (view mobile)! Reiki Healing Association Membership (view mobile)! Push Button Marketer - Automation Software For Internet Marketers! Biz Opportunity - Start Your Own Online Embroidery Business From Home (view mobile)! Gray Hair No More - Reverse Gray Hair - 2018 Update! Five Of The Top Converting Dating And Relationship Offers For Women! Pet Sitting Business Start Up Kit (view mobile)! Feel Tennis Online Video Instruction Courses (view mobile)! This Is A Sports Spread Betting Subscription Service That Generates Consistent Monthly Returns For Its Members! Pirate Ship Playhouse Plans (view mobile)! Sex Advice Education Programs By Gabrielle Moore! Robust 4-week Nutrition Education For Those Who Want To Quit Yo-yo Dieting And Learn How To Eat Healthy Forever! Fulfilling Relationships Course - Become Skilled (view mobile) 15-hour Video Course In Which You Learn 17 Relationship Skills To Create A Fulfilling Love Life, And Inspiring Friendships! Evergreen Web-store With 270+ Subliminal Mp3s In All Areas Of Self Improvement And The Law Of Attraction! Fearless Flow Conversation System! Full Shopping Cart- Brainwave Recordings, Health, Wealth, Prosperity, Manifestation, Success! Personal Development Offer: Killer Hook, Amazing Conversions! Push Button Marketer - Automation Software For Internet Marketers! Get Free Flights With Travel Hacking! 30-day Crash Course: Transgender Voice Feminization (view mobile)! Aquarius Man Secrets (view mobile)! How To Write Songs That Sell (view mobile)! Public Speaking Certification (view mobile)! Speak To Spark Arousal - For Men (view mobile) 5+ Hours Of Video Demonstration Modules That Help Men Start And Move Through Conversation With Ease!

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Mission News Theme by Compete Themes.