WordPress, as we all know, is one of the most popular free and open source content management system based on PHP and MySQL. At the time of writing this article WordPress, 4.9 has been downloaded 153,263,827 times and it’s still growing.
On the other hand, Python is an interpreted high-level programming language for general-purpose programming. Created by Guido van Rossum and first released in 1991, Python has a design philosophy that emphasizes code readability, notably using significant whitespace. Due to its elegant syntax, it’s really easier to read, which make it one of the most popular programming language.
Now, what if you want to use Python scripts in WordPress.. is it really possible ? ….
Well, the answer is yess… in this article .. we gonna show it .. how can you use .. python scripts in a WordPress blog.
So let’s create a python file (.py) and store it aside for now. Now let’s create a WordPress plugin and register a shortcode:
<?php # -*- coding: utf-8 -*-
/* Plugin Name: Python embedded */
add_shortcode( 'python', 'embed_python' );
function embed_python( $attributes )
$data = shortcode_atts(
'file' => 'hello.py'
$handle = popen( __DIR__ . '/' . $data['file'], 'r' );
$read = '';
while ( ! feof( $handle ) )
$read .= fread( $handle, 2096 );
pclose( $handle );
Now you can use that shortcode in the post editor with
Put the Python scripts you want to use into the same directory as the plugin file. You can also put them into a directory and adjust the path in the shortcode handler.
You may Also Like
/ September 24, 2020
What is C++ C++ is a programming language developed by Bjarne Stroustrup in 1979 at Bell Labs. Originally, it was...
/ September 9, 2020
It has become highly essential to use a PHP MVC framework to develop custom web applications and there are many...
/ September 2, 2020
In the world of programming languages, there is no respite for breakthroughs and innovations. The developers are always in search...
/ June 16, 2020
What is Python? Python is an interpreted, high-level, general-purpose programming language. It was created by Guido van Rossum, and released...
/ May 18, 2020
LAMP stands for Linux, Apache, MySQL, and PHP, Perl, or Python. It offers a great alternative to commercial software packages. ...
/ May 7, 2020
Java is an object-oriented language similar to C++, but with advanced and simplified features. Java is free to access and...
/ April 29, 2020
Cascading Style Sheets, fondly referred to as CSS, is a style sheet language used to define visual appearance and formatting...
/ April 23, 2020
First developed by Tim Berners-Lee in 1990, HTML is short for Hypertext Markup Language. HTML is a computer language devised...
/ April 17, 2020
Django is an MVT web framework used to build web applications. Django is an excellent web framework for Python that...
/ April 14, 2020
As one of the first PHP frameworks created, CakePHP is among the most popular PHP frameworks today. CakePHP, being a...