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
/ July 23, 2021
How to Create a Glowing Text using CSS Step 1: Adding text to HTML <h1 class="glow">This is an example...
/ July 19, 2021
/ June 30, 2021
A modal is a dialog box/popup window that is displayed on top of the current page: How To Create a...
/ June 22, 2021
In today's world, when technology is so advanced, the most important skill a person should have is to know how...
/ June 17, 2021
Blockchain is a technology that is rapidly expanding with the development of new platforms and applications. Blockchain is an open...
/ June 15, 2021
/ June 8, 2021
/ June 7, 2021
/ June 5, 2021
/ May 31, 2021
Learn How to Create a full screen video background using HTML, CSS Adding HTML <div class="videobg"> <video src="https://adaptabiz.com/wp-content/uploads/2021/05/Pexels-Videos-1234162.mp4" loop muted...