Skip to content

Instantly share code, notes, and snippets.

@rezakianoosh
Last active November 5, 2015 07:03
Show Gist options
  • Save rezakianoosh/252b9076a8baf7ff4dd9 to your computer and use it in GitHub Desktop.
Save rezakianoosh/252b9076a8baf7ff4dd9 to your computer and use it in GitHub Desktop.
Conditional wordpress Tags http://ronakweb.com
<?php
if ( is_front_page() && is_home() ) {
// Default homepage
} elseif ( is_front_page() ) {
// static homepage
} elseif ( is_home() ) {
// blog page
} else {
//everything else
}
///////////////////////
if ( is_page() && $post->post_parent > 0 ) {
echo "This is a child page";
}
//////////////
add_action( 'the_content', 'baw_add_social_buttons' );
function baw_add_social_buttons( $content ) {
if ( ! is_admin() && is_main_query() ) {
return $content . function_from_a_social_plugin();
}
return $content;
}
//////
add_action( 'pre_get_posts', 'baw_modify_query_exclude_category' );
function baw_modify_query_exclude_category( $query ) {
if ( ! is_admin() && $query->is_main_query() && ! $query->get( 'cat' ) ) {
$query->set( 'cat', '-5' );
}
}
////
add_filter( 'comments_open', 'my_comments_open', 10, 2 );
function my_comments_open( $open, $post_id ) {
$post = get_post( $post_id );
if ( 'page' == $post->post_type )
$open = false;
return $open;
}
//////
is_page();
// When any single Page is being displayed.
is_page( 42 );
// When Page 42 (ID) is being displayed.
is_page( 'Contact' );
// When the Page with a post_title of "Contact" is being displayed.
is_page( 'about-me' );
// When the Page with a post_name (slug) of "about-me" is being displayed.
is_page( array( 42, 'about-me', 'Contact' ) );
// Returns true when the Pages displayed is either post ID 42, or post_name "about-me", or post_title "Contact". Note: the array ability was added at Version 2.5.
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment