Created
September 13, 2017 18:42
-
-
Save cobaltapps/7b0b4c3c776ebf20da95eff536c2969f to your computer and use it in GitHub Desktop.
An example of how to use WordPress Conditional Tags inside of custom functions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'theme_before_content', 'my_banner_ad' ); | |
/* | |
* This conditional example ensures that the banner ad only | |
* displays on the front page by returning nothing if it | |
* is NOT the front page. | |
*/ | |
function my_banner_ad() { | |
if ( ! is_front_page() ) | |
return; | |
echo '<img src="http://example.com/link-to-my-banner.png">'; | |
} | |
add_action( 'theme_before_content', 'my_banner_ad' ); | |
/* | |
* This conditional example ensures that the banner ad only | |
* displays on the front page by only echoing the image code | |
* if it IS the front page. (same result as above, but different method) | |
*/ | |
function my_banner_ad() { | |
if ( is_front_page() ) { | |
echo '<img src="http://example.com/link-to-my-banner.png">'; | |
} | |
} | |
add_action( 'theme_before_content', 'my_banner_ad' ); | |
/* | |
* This conditional example ensures that the banner ad only | |
* displays on the front page OR a single page by only echoing the image code | |
* if it IS the front page OR it is a single page. | |
*/ | |
function my_banner_ad() { | |
if ( is_front_page() || is_page() ) { | |
echo '<img src="http://example.com/link-to-my-banner.png">'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment