Home > Blockchain >  How do I Add PHP code in WordPress POST without using a plugin
How do I Add PHP code in WordPress POST without using a plugin

Time:07-06

I am trying to add php code(2000 lines) to WordPress post manually without using any plugin or third party tool. But I have not been successful in this... If anybody knows how I can do this please feel free to post an answer. So far I have been able to add my php code to WP Page but not WP Post. I will be looking forward to you! Thanks!

CodePudding user response:

I was able to do this by creating a separate .php file in my theme "twentytwentytwo" folder and then I pasted the following code in it...

"<?php /*

  • Template Name: new Theme

  • Template Post Type: post */ ?>"

"" ""

By doing this I created a Separate theme for my post. Then simple pasted my php code under the get_header() line.... After this I logged in to my WP admin and clicked on the edit post and in the template dropdown section I found my theme name "new Theme" just selected that and published. Job done!

CodePudding user response:

Use 'the_content' filter https://developer.wordpress.org/reference/hooks/the_content/

example :

function custom_content($content)
{
    global $post;
    
    if ($post && $post->post_type == 'post') {
        
        if ($post->ID == '145'()) { // target a specific post by ID
            // do something
        }
    }
    
    return $content;
}
add_filter('the_content', 'custom_content');
  • Related