Title: conditional function if page exists
Last modified: August 19, 2016

---

# conditional function if page exists

 *  Resolved [bfkouba](https://wordpress.org/support/users/bfkouba/)
 * (@bfkouba)
 * [16 years ago](https://wordpress.org/support/topic/conditional-function-if-page-exists/)
 * I’m VERY new at all of this. I would like to make a conditional statement in 
   my sidebar that shows a piece of text if a page with a specified id is published(
   instead of draft or pending review)… so something like this:
 *     ```
       <?php
       if(page_is_published('293')){ ?>
       <a href="/next-weeks-movies">Next Week's Videos</a>
       <?php }else{} ?>
       ```
   
 * Can someone help me? Thank you!
    – Ben

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [16 years ago](https://wordpress.org/support/topic/conditional-function-if-page-exists/#post-1487942)
 * Totally untested but what about:
 *     ```
       <?php
       $page_id = 293;
       if( get_page($page_id) ) { ?>
       <a href="/next-weeks-movies">Next Week's Videos</a>
       <?php }else{} ?>
       ```
   
 * [http://codex.wordpress.org/Function_Reference/get_page](http://codex.wordpress.org/Function_Reference/get_page)
 *  Thread Starter [bfkouba](https://wordpress.org/support/users/bfkouba/)
 * (@bfkouba)
 * [16 years ago](https://wordpress.org/support/topic/conditional-function-if-page-exists/#post-1487981)
 * Seemed like it would… but wordpress still finds the page even if it’s a draft.
 * I don’t know. Basically I want to hide the link if the page is a draft. There’s
   gotta be a way.
 * Anyone?
 *  Thread Starter [bfkouba](https://wordpress.org/support/users/bfkouba/)
 * (@bfkouba)
 * [16 years ago](https://wordpress.org/support/topic/conditional-function-if-page-exists/#post-1487986)
 * Hey I figured it out!
 * For anyone else wanting to the same things… here’s what I got:
 *     ```
       $page_id = 284; //the id of the page you're checking to see if it's published
       $page_data = get_page($page_id);
       if($page_data->post_status == 'publish'){ ?>
       <!-- Put the HTML here that you want to display if the page is published -->
       <?php }else{} ?>
       ```
   
 *  Thread Starter [bfkouba](https://wordpress.org/support/users/bfkouba/)
 * (@bfkouba)
 * [16 years ago](https://wordpress.org/support/topic/conditional-function-if-page-exists/#post-1487987)
 * btw… THANK YOU to esmi. That tip got me going in the right direction. I appreciate
   the support.
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [16 years ago](https://wordpress.org/support/topic/conditional-function-if-page-exists/#post-1488055)
 * You’re very welcome. 🙂 Thanks for posting a working solution.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘conditional function if page exists’ is closed to new replies.

## Tags

 * [conditional](https://wordpress.org/support/topic-tag/conditional/)
 * [page](https://wordpress.org/support/topic-tag/page/)
 * [published](https://wordpress.org/support/topic-tag/published/)

 * 5 replies
 * 2 participants
 * Last reply from: [esmi](https://wordpress.org/support/users/esmi/)
 * Last activity: [16 years ago](https://wordpress.org/support/topic/conditional-function-if-page-exists/#post-1488055)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
