Subpage get parent page slug
-
I’m building a template and have the following code
<?php if (is_page()) { ?> <?php $cssdir = $post->post_name; ?> <link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/page.css" type="text/css" media="screen" /> <link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/<?php echo $cssdir; ?>/style.css" type="text/css" media="screen" /> <?php } ?>
to select stylesheets based on the pagenames, which works fine and dandy, until you load a subpage.
On a page the code generates the css URL like this:
https://www.mywebsite.com/wp-content/themes/mytheme/pagename/style.css – fine, but on a subpage:
https://www.mywebsite.com/wp-content/themes/mytheme/pagename/subpagename/style.css
I just want it to grab the parent page’s style.css, which could be done by the parent page’s slug, but I’m not sure how to do this.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Subpage get parent page slug’ is closed to new replies.