I am trying to add conditional logic to blog posts, but I cannot work out how to do that. Both
if ( is_singular( 'post' ) ) {
and
if ( is_single() ) {
return false
Ok, after reading your comment i know why it isn't working. You cannot use it directly in functions.php.
Why
functions.php runs way before the is_single()
method is available.
How to use it
single.php
etc.Example
You can place this directly in your functions.php
add_action('wp','testing_is_single_method');
function testing_is_single_method() {
if(is_single()) {
add_action('wp_footer', function() {
?>
<script type="text/javascript">alert('HEY THIS IS A SINGLE (BLOG) POST');</script>
<?php
});
}
}
Regards, Bjorn