change slug for multiple pages with same root
-
Hi there,
Sorry if this question is naive, but I can’t seem to figure it out. I took Syahir’s code to trigger a custom header for a single page:
<?php /* Only add this line if you're working on an empty functions.php file */
/**
* Manually set different header image for individual pages
*/
function graphene_custom_header_image( $img_url ){
/* Replace page-slug with the actual page slug */
if ( is_page( 'page-slug' ) ) return 'http://www.new-image.url';
return $img_url;
}
add_filter( 'graphene_header_image', 'graphene_custom_header_image' );and it works perfectly. I’m wondering whether I can create a wildcard indicator for any page that includes the slug. In other words, if the primary page slug for the page I want to have the custom header is” a-main”, can I use something like if ( is_page(‘a-main/*)) to load the custom header on all pages with that root?
specifically, http://artemisediting.com/a-main/
Thank you,
Diana
AdminTry this:
/**
* Manually set different header image for individual pages
*/
function graphene_custom_header_image( $img_url, $post_id = false ){
if ( ! $post_id ) return $img_url;
$current_post = get_post( $post_id );
if ( stristr( $current_post->post_name, 'a-main' ) !== false ) return 'http://www.new-image.url';
return $img_url;
}
add_filter( 'graphene_header_image', 'graphene_custom_header_image', 10, 2 );Thanks, Syahir,
It still works for the top page, but not for the others. Here’s what I entered, just in case I made a stupid mistake:
/*** Manually set different header image for individual pages*/
function graphene_custom_header_image( $img_url, $post_id = false ){
if ( ! $post_id ) return $img_url;
$current_post = get_post( $post_id );
if ( stristr( $current_post->post_name, 'a-main' ) !== false ) return 'http://artemisediting.com/wp-content/uploads/2013/04/bspaheader.png';
return $img_url;
}
add_filter( 'graphene_header_image', 'graphene_custom_header_image', 10, 2 );I’m also curious: what do the 10 and 2 signify?
Thanks so much,
Diana
AdminAh… in your site there is only one page that contains
a-main
in its slug. The other pages are children of that page, but do not havea-main
in their slugs. Try this then:/**
* Manually set different header image for individual pages
*/
function graphene_custom_header_image( $img_url, $post_id = false ){
if ( ! $post_id ) return $img_url;
$parent_id = 65; /* Change to the ID of the parent page */
$current_post = get_post( $post_id );
if ( in_array( $parent_id, array( $current_post->ID, $current_post->post_parent ) ) ) return 'http://www.new-image.url';
return $img_url;
}
add_filter( 'graphene_header_image', 'graphene_custom_header_image', 10, 2 );10
is the priority for the function, while2
is the number of arguments it accepts.Ahhh. Or maybe I should just change the slugs to a-main-whatever?
AdminDid you try the last code I provided?
yes, but got this:
Parse error: syntax error, unexpected T_RETURN in /home/content/c/o/r/corporatelogin/html/artemisediting/wp-content/themes/dianas-graphene/functions.php on line 10
looking for extra spaces
AdminAh, sorry the code was missing a single closing parentheses. I’ve corrected the above code. Please try again.
It doesn’t seem to do anything. 🙁
AdminDid you change the
$parent_id
to the actual ID of the parent page, i.e. the page with thea-main
slug?
Viewing 10 posts - 1 through 10 (of 16 total)
- 1
- 2
- You must be logged in to reply to this topic.