We noticed you're using an ad blocker

Our website is made possible by displaying online advertisements to our visitors. Please consider supporting us by disabling your ad blocker.

Laravel blade template in WordPress theme

world cup 2022

FootballDesk

Get update standing EPL, UEFA, LaLiga and more

Get Now

There is several php template engine but Blade template engine is the most popular and simplistic way to write php code along with HTML. The popular Laravel Framework use it out of the box. If you are laravel developer then you already know how cool the Blade syntax. If you are not a Laravel developer you are also be impressed with Blade syntax after see the few examples.

In the WordPress template, where we need to write php code along with HTML then you know as a WordPress developer how the scenario is. Let's take a look a simple example but when it will be a big code it will be more complex. After showing some code example I'll show you how to integrate the blade template engine to your WordPress theme just 3 simple steps.

 

In normal PHP with HTML

<?php for($i;$i<5;$i++) { 
	if($i==2){ ?>
		<p> Name: <?php echo $name; ?>
	<?php } else { ?>
  	<p>Value: <?php $i; ?></p>
  	<?php } ?>
<? } ?>

In Blade syntax, you can do it with simple clean syntax and elegant way.

@for($i;$i<5;$i++)
   @if($i==2) 
     <p> Name: {{$name}} </p>
   @else
     <p> Value: {{$i}} </p>
   @endif
@endfor

Let's see more examples.

foreach loop

@foreach($data as $row)
  <div>
     Name: {{$row->name}} <br>
     Age: {{$row->age}} <br>
  </div>
@endforeach

 if-else Conditional statement

@if($condition)
   <p> Smith </p>
@else
   <p> Adam </p>
@endif

include file 

@include('abc.php')

wpquery WordPress loop

@wpquery(array('post_type' => 'post'))
  {{the_title()}}
@wpempty
  <p> No post found </p>
@wpend 

To know more about Blade template documentation

 

Now let's see the installation process with WordPress theme

Step 01: Download Blade template

Step 02: Extract the downloaded folder and copy the blade folder then paste the folder into your WordPress theme.

Step 03: Now open the functions.php file and simply include the line include("blade/blade.php")

Finished! Now you can use blade syntax in your WordPress theme.


Share on




Related Post - Latest Post


Tinkerpad - A minimal Laravel code editor

What's new in Laravel 9

Make laravel site super fast by page-cache!

Laravel maintenance mode bypass by Secret Route!

Laravel database backup automatically - cPanel shared hosting, VPS

Laravel Datatables - Ajax, Column, Buttons, Customization