Display Message on Post Preview Page in WordPress

By | November 25, 2013

WordPress having an option called Preview, while writing a post if we want to check the structure or alignment we can use preview option. Preview option is placed in Right Side of Edit Post Page. Here is the PHP code to display a message that you are in preview page.

 

 

is_preview()

is_preview() function will return the boolean value of true or false. If the page is preview, then it will return true else it will return false.

 

PHP Code

Include the below coding in header.php file just after the <body> tag

1
2
3
4
5
6
7
8
9
10
11
<?php
if(is_preview())
{
echo "<div class='preview-box'>This Page is Preview Page</div>";
}
?>

 

Stylesheet

Include the below coding in style.css file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
.preview-box
{
position: fixed;
bottom: 0px;
background: #E54324;
color: #fff;
width: 100%;
padding: 12px 0px;
font-weight: bold;
}

 

After including this file in header.php and style.css file then alert message will be shown in bottom.

Display Message on Post Preview Page in WordPress

Display Message on Post Preview Page in WordPress

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

tawse-bangalay