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
/ January 6, 2021
In Python, there is a module, which allows you to copy a mutable object so that changes made in the...
/ December 15, 2020
What is Unity? According to Wikipedia : Unity is a cross-platform game engine with a built-in IDE developed by Unity...
/ December 8, 2020
Cascading Style Sheets, fondly referred to as CSS, is a style sheet language used to define visual appearance and formatting...
/ December 1, 2020
Mobile applications have come a long way since the basic arcade game “Snake,” which many consider the first mobile application....
/ November 23, 2020
In this tutorial we gonna learn how to create a simple login form using HTML and CSS Step 1) Add...
/ November 16, 2020
Information technology is growing rapidly and it is not slowing down, neither it will according to the pace and the...
/ November 9, 2020
What is PHP ? PHP is a server-side scripting language that is used to develop Static websites or Dynamic websites...
/ November 6, 2020
Machine Learning is undeniably one of the most influential and powerful technologies in today’s world. Machine Learning is enabling computers...
/ November 2, 2020
A modal is a dialog box/popup window that is displayed on top of the current page: How To Create a...
/ October 29, 2020
Blockchain is a technology that is rapidly expanding with the development of new platforms and applications. Blockchain is an open...