1

The is_page() with post id, post slug isn't working. Below is the code i have been using in divi child theme at the end of the functions.php file.

function addingcattocatlist($cat_list){

        if ( is_page('blog') ) {
            $cat_list = 'blog: '. '' .$cat_list;
        }   
        return $cat_list;
}
add_filter('the_category' , 'addingcattocatlist', 10);
  • are you using a custom page template? whats the file name? – Sagive SEO Jan 20 '16 at 16:37
  • I am not using custom page template. I just want that on /blog/ page , when the categories are listed, blog: text needs to be added before the categories list. – Muyassir S. Jan 20 '16 at 18:44
  • Are the conditionals actually available when that filter is being called? – Welcher Jan 20 '16 at 23:37
  • 1
    is 'blog' the page you have set as 'posts page'? – Michael Jan 21 '16 at 5:26
  • @Welcher , Sorry i am not sure if the conditions are actually available when that filter is called. It might be the issue. how can i check it ? – Muyassir S. Jan 21 '16 at 14:34
2

Try this:

if ( is_front_page() && is_home() ) {
  // Default homepage
} elseif ( is_front_page() ) {
  // static homepage
} elseif ( is_home() ) {
  // blog page
} else {
  //everything else
}

Source: http://codex.wordpress.org/Conditional_Tags

  • I have already researched this on internet. Please, reply why the is_page isn't working in the above case. tested by entering the id and slug there. and it didn't worked ! – Muyassir S. Jan 20 '16 at 18:45
1

OK @Muyassir S. - we are missing some information to understand the problem.

We basicly dont know if the "page" you are talking about is a category page, Your home page or a custom page - meaning: which file is being used to show that blog?

here are two possible solutions.

If we are talking about a category / page with slug:

if(is_category('blog')) {
   // add whatever you want here
}
  • should be placed inside category.php template

If you went to: Settings > Reading
and set the posts page over there then its a page and can be accesses like this.

$blogPgid = get_option('page_for_posts');

if(get_the_ID() == $blogPgid) {
       // add whatever you want here
}
  • should be placed inside page.php template.

Let me know if this helps

EDIT 1: here is what i would do.

1st. Just copy page.php in your theme and name the new copy page-blog.php Now, add a in the top of that page these tag (above everything).

<?php
/*
Template Name: Blog Page
*/
?>

2nd. go back to that page in WP admin and pick that page template. Now you have a page / file that you can control and add whichever specific stuff you'd like.

  • It's a custom page using the default template. – Muyassir S. Jan 21 '16 at 14:22
  • what makes its custom? did you try the second option? – Sagive SEO Jan 21 '16 at 14:26
  • a page /blog has been created and with divi theme builder, blog shortcode has been used on it. It's actually not the default posts page but a page with blog shortcode on it that can list posts with different options. – Muyassir S. Jan 21 '16 at 14:39
  • OMG... didnt knew that - did you just added that to your question?. In any case - well, see edit – Sagive SEO Jan 21 '16 at 15:08
  • Thank you, it helped. Also i found the reason why the is_page isn't working in functions.php file on the following link in stack. wordpress.stackexchange.com/questions/21418/… – Muyassir S. Jan 21 '16 at 16:36
0

functions.php is processed way before you can know which page is being loaded. Instead of assigning value to variable put your code into function and use that function in page.php template.

Why isn't is_page working when I put it in the functions.php file?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.