include php file if page_id matches

I think this is a simple question:

I’m building a plugi, and up until now, if i wanted to include a php file, i would have to know the page_id – i would put the following command in page.php (or whatever page template i’m using):

Read More
if (is_page(4552)) {
     include WP_PLUGIN_DIR .'/file_to_include.php';
}

now, A bit more background: i now have a hook that creates a post on activation, and saves the post_id using update_options. so, that’s how i know what $page_id is.

So, to summarize – how do i dynamically write the code above – in my plugin – assuming I know the $page_id?

Thanks for helping!

Related posts

Leave a Reply

1 comment

  1. Make sure to add it to a hook that fires at or after ‘wp’ ;

    Example:

    add_action( 'wp', 'your_function_name');
    
    function your_function_name(){
        global $post;
    
    $your_page_id = get_option('your_option_name');
    
        if( $post->ID == $your_page_id ):
    //your include 
    endif;
    }