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
/ April 29, 2022
/ April 19, 2022
/ April 2, 2022
/ February 19, 2022
/ February 15, 2022
Many a times, there is necessity of converting Color image into Black and White or Grayscale. Here in this very...
/ February 4, 2022
There are many a times, when you’re going to need a countdown clock for your project. You may have an...
/ January 20, 2022
How to Create an Avatar image with CSS Step 1) Add HTML: <h2>How to create Avatar Images with CSS</h2> <img...
/ January 13, 2022
How to Change Background Images on Scroll with CSS. Step 1) Add HTML: <div class="bg-image img1"></div> <div class="bg-image img2"></div>...
/ January 3, 2022
/ December 21, 2021
What is Drupal ? Drupal is free, open source software that can be used by individuals or groups of users,...