I need to hide a specific portion of my footer file if the page being displayed is the “artists page”. The content i was told to hide was all jumbled together in the footer so i separated that part, and placed it in its own file. lets call that file, file X.php, which I placed back on the footer via an include.
This is the link that’s telling me that my page id is “4”:
wp-admin/post.php?post=4&action=edit
I need file X.php to only show, when the page being shown to the user is not artists page. So essentially, i need file X.php to show on every page except the artists page.
I used a simple conditional like so:
if ( ! is_page( 'artists' ) ) { include('file X.php'); }
//i used this to target the page by page name
/=========
if ( ! is_page( '4' ) ) { include('file X.php'); }
//i used this to target the page by page id
and the page never hides. its always shown.
i referenced this link/page: https://codex.wordpress.org/Conditional_Tags
and other pages like it, including posts here on SO but yeah, not sure what I’m doing wrong.
I don’t get any errors or anything broken. When i leave that code in place(by page title or id), the footer shows as its supposed on the other pages, but unfortunately shows on the artists page as well when i need it not to.
Any help is greatly appreciated. Thanks in advanced.
EDIT***
i used: var_dump( get_queried_object() );
and this is what it returned:
object(stdClass)#376 (17) {
["term_id"]=> &int(3)
["name"]=> &string(15) "featuredArtists"
["slug"]=> &string(15) "featuredartists"
["term_group"]=> int(0)
["term_order"]=> string(2) "11"
["term_taxonomy_id"]=> int(3)
["taxonomy"]=> string(8) "category"
["description"]=> &string(0) ""
["parent"]=> &int(0)
["count"]=> &int(3)
["filter"]=> string(3) "raw"
["cat_ID"]=> &int(3)
["category_count"]=> &int(3)
["category_description"]=> &string(0) ""
["cat_name"]=> &string(15) "featuredArtists"
["category_nicename"]=> &string(15) "featuredartists"
["category_parent"]=> &int(0)
}
Remove
query_posts
.get_queried_object()
should return the page object regardless of what is being showed on it.As you can see from the
var_dump()
, a category object is returned where as it should return the page object, which means thatis_page()
will always return false although it is a true page.is_category()
will return true on this page however as the page has been set as a category page.What all of this means is that the main query object changed on the page, and the only function that can do that is
query_posts
(or you have used$wp_query
as a local variable to assign a custom query to it). This is the main reason why you should never ever usequery_posts
as it breaks the main query object, it sets the main query object to the current custom query, which breaks all the conditionals and the queried object. Just for interest sake, before and after yourquery_posts( 'cat=3' );
, addvar_dump( is_page() );
andvar_dump( is_category() );
and check the results.As solution, switch to
WP_Query
to run custom queries with (or useget_posts
for non paginated queries)