skip to Main Content

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!

2

Answers


  1. Chosen as BEST ANSWER

    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!


  2. 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');
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search