kbu
kbu

Reputation: 389

Wordpress functions in Laravel

could anyone explain, is it possible include WP functions into Laravel blade.template?

I have WP installation and want create one folder for an app on Laravel. These functions i want include:

<?php require( '../wp-load.php' ); ?>
<?php get_header(); ?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

How i can implement this feature? Thx in advance!

Upvotes: 0

Views: 1574

Answers (1)

Nabil Kadimi
Nabil Kadimi

Reputation: 10394

1. Add WordPress to app/vendor

Download WordPress into the vendor folder (./vendor/wordpress)

User require in composer.json, see (3).

2. Find the function location

Check the Codex page for the function you need, let's say esc_url(), as you can see in that page, the function resides in wp-includes/formatting.php

3. Include the file containg the function

Include that file, use your composer.json file then run the command composer update

"require": {
    ...
    "johnpbloch/wordpress": "4.*"
},
"autoload": {
    ...
    ...
    ...
    "files": [
        ...
        "wordpress/wp-includes/formatting.php"
    ]
},

4. Use the function in Blade

{{-- file: app/views/example.blade.php }}

{{ esc_html( '<a href="http://www.example.com/">A link</a>' ) }}

This outputs:

&lt;a href=&quot;http://www.example.com/&quot;&gt;A link&lt;/a&gt;

Upvotes: 3

Related Questions