I'm trying to replace the main content area on individual pages to say Coming soon (on two pages, but not the rest of the website). Also only want to make it so people who aren't logged in see the coming soon page and people who are logged in see the actual page, so it can be worked on. So far I have this code, which doesn't work.
add_action( 'the_content', ‘ind_coming_soon_page’ );
function ind_coming_soon_page( $content ) {
if ( is_user_logged_in() ) {
return;
} else {
if (is_page( 10142 || 9035 )) {
echo “Coming Soon”;
} else {
return $content;
}
}
}
I keep getting the error below when trying to enable the plugin (and I don't know it works yet either), the error relates to line 18 which is echo "Coming Soon!";
:
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /var/www/vhosts/vagish.com/httpdocs/wp-content/plugins/test/coming-soon.php on line 18
A couple things here. The first is that I think you should be using add_filter( 'the_filter', 'ind_coming_soon_page' );
instead of add_action()
. I don't think there's an action hook for the_content
. Here's a link to the docs on the_content()
filter
Next, I think there are some issues with your code. You need to set the string "Coming Soon" to the $content
variable. The is_page()
function is close, but the parameters are wrong.
add_filter( 'the_content', ‘ind_coming_soon_page’ );
function ind_coming_soon_page( $content ) {
if ( is_user_logged_in() ) {
return;
} else {
if (is_page( array( 10142, 9035 )) {
$content = "Coming Soon";
}
}
}
return $content;
}
I moved some stuff around a bit for you. Basically, if the user is logged in, return out of there. If they're not and they're on one of those two page ids (I switched it to an array heres the reference on the codex: http://codex.wordpress.org/Function_Reference/is_page) then set the $content variable to "Coming Soon". Then regardless if those conditions are met, we return the $content
variable.
This is untested but I'm pretty sure it will work.