Question

I just started using wordpress. Now I'm trying to create a theme for a static web page I wrote.

For that web page I'm using barbajs, which is why I have a html tag (in my case a section tag) with a custom data-namespace attribute.

Also I use body classes for each page.

So basically a page looks something like that:

<body class="page-about">
   <main>
      <section data-namespace="about">
      </section>
   </main>
</body>

I was able to use a function from this question to append a body class, but since I don't really need all the crap classes that wp comes with (like page page-id-7 page-template, etc), I'd like to create a custom function.

So basically I want something like that:

In the template I'd like to define a namespace variable, or something similar, which will then be used by a function to place wherever I need it.

something like that:

<?php
/* Template Name: About Template */
$namespace = 'about';
?>
<body class="page-<?php get_namespace() ?>">
   <main>
      <section data-namespace="<?php get_namespace() ?>">
      </section>
   </main>
</body>

The get_namespace function should then be defined in the functions.php.

Can someone help me with the function, or recommend a better way to do it?

I appreciate all the help!

UPDATE

Now that I've worked on a couple wordpress pages, I understand the way bodyclass operates better. My initial Problem was pretty much only, that I used my own page class which I can replace with the ones created by wordpress in the css, I guess I should simply use static text for the data-namespace attribute, which works fine, as long as I don't include that section in the header.

Was it helpful?

Solution

If I am understanding you correctly you could use get_page_template_slug(). For example...

<?php echo get_page_template_slug( $post->ID ); ?>

Although, to be honest I don't see the point of doing this over using body_class().

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top