How to get blog slug name?
-
- Jr. Bludit
- Posts: 2
- Joined: Wed Sep 13, 2023 2:02 am
- Has thanked: 1 time
- Been thanked: 1 time
Hello,
I'm developing a theme, and I want to automatically add blog menu/link (if home is a static page) to the navigation bar.
So far what I got is $site->uriFilters('blog') will get the blog URL.
But I still can't find the way to get the slug name.
For example, the slug being inputted is /stories/ or /articles/ or anything else.
How to get this slug name?
Thank you.
I'm developing a theme, and I want to automatically add blog menu/link (if home is a static page) to the navigation bar.
So far what I got is $site->uriFilters('blog') will get the blog URL.
But I still can't find the way to get the slug name.
For example, the slug being inputted is /stories/ or /articles/ or anything else.
How to get this slug name?
Thank you.
- CCDzine
- Ssr. Bludit
- Posts: 13
- Joined: Thu Sep 07, 2023 11:49 pm
- Location: Sierra Nevada Mountains, Califonia
- Has thanked: 4 times
- Been thanked: 6 times
- Contact:
Try getting the field value.
.
This is what I do to use the slug as the menu entry...
Code: Select all
$site->getField( 'uriBlog' );
This is what I do to use the slug as the menu entry...
Code: Select all
$blog_uri = $site->getField( 'uriBlog' );
if ( ! empty( $blog_uri ) ) {
// Use sprintf() if you need to echo later.
printf(
'<li><a href="%s">%s</a></li>',
$site->url() . str_replace( '/', '', $blog_uri ) . '/',
ucwords( str_replace( [ '/', '-', '_' ], ' ', $blog_uri ) )
);
}
Greg Sweet