Display book name in page meta title tag #1322

Open
opened 2026-02-05 00:36:38 +03:00 by OVERLORD · 6 comments
Owner

Originally created by @over-soul on GitHub (Aug 28, 2019).

Describe the feature you'd like
Right now, pages and chapters only show the current page name in the meta title (and even this is trimmed). This can be problematic if you bookmark two pages or two chapters that have the same name but are from different books (also not good for SEO if your site is public). Ideally, the book name should be included in the title of every page (or chapter) that is under that book. (see screenshot below for an example).

Describe the benefits this feature would bring to BookStack users

  1. Clarify which book a page or chapter is from
  2. Related to #1, make bookmarks a lot clearer since two pages could have the same name but be from different books
  3. SEO improvement

Additional context
Meta_Title

Originally created by @over-soul on GitHub (Aug 28, 2019). **Describe the feature you'd like** Right now, pages and chapters only show the current page name in the meta title (and even this is trimmed). This can be problematic if you bookmark two pages or two chapters that have the same name but are from different books (also not good for SEO if your site is public). Ideally, the book name should be included in the title of every page (or chapter) that is under that book. (see screenshot below for an example). **Describe the benefits this feature would bring to BookStack users** 1. Clarify which book a page or chapter is from 2. Related to #1, make bookmarks a lot clearer since two pages could have the same name but be from different books 3. SEO improvement **Additional context** ![Meta_Title](https://user-images.githubusercontent.com/29743024/63850224-7f9acf80-c98b-11e9-9fb5-1ecce4b75196.png)
OVERLORD added the Open to discussion🎨 Design labels 2026-02-05 00:36:38 +03:00
Author
Owner

@over-soul commented on GitHub (Sep 1, 2019):

Hi @ssddanbrown,

Wondering what you think about this one?

Thanks!

@over-soul commented on GitHub (Sep 1, 2019): Hi @ssddanbrown, Wondering what you think about this one? Thanks!
Author
Owner

@ssddanbrown commented on GitHub (Sep 7, 2019):

Thanks for raising your thoughts @over-soul.

Personally, I'm not too sure about this one. The main benefit appears to revolve around bookmarks, but bookmarks can often be easily renamed if required. In my mind the title provides the following features:

  1. Provides quick-glance context of the tab/window content.
  2. Provides initial context to screen-reader/accessibility technologies.
  3. Provides a title for SEO purposes.

I care more about the first two mainly. SEO is good to consider but not a primary focus for BookStack.

For (1.) I think it's more beneficial to have the page first. Will of course depend on the setup and content but In think for most setups the page name will provide the best info to dictate what's in the tab/window. Could tack the book name on the end but it'll likely be hidden within a tab in the majority of cases.

For (2.) it couple help to include the book name but not sure if it will then be too lengthy. Think I'd have to test it out with a screen-reader to see what gives the best experience.

@ssddanbrown commented on GitHub (Sep 7, 2019): Thanks for raising your thoughts @over-soul. Personally, I'm not too sure about this one. The main benefit appears to revolve around bookmarks, but bookmarks can often be easily renamed if required. In my mind the title provides the following features: 1. Provides quick-glance context of the tab/window content. 2. Provides initial context to screen-reader/accessibility technologies. 3. Provides a title for SEO purposes. I care more about the first two mainly. SEO is good to consider but not a primary focus for BookStack. For (1.) I think it's more beneficial to have the page first. Will of course depend on the setup and content but In think for most setups the page name will provide the best info to dictate what's in the tab/window. Could tack the book name on the end but it'll likely be hidden within a tab in the majority of cases. For (2.) it couple help to include the book name but not sure if it will then be too lengthy. Think I'd have to test it out with a screen-reader to see what gives the best experience.
Author
Owner

@over-soul commented on GitHub (Apr 14, 2020):

Hi @ssddanbrown,

I think it is important to show which book a chapter or page is from since you could have pages that have the same name open in tabs and you have to click through multiple tabs to find the page you are looking for. If the book name is in the title, while it might be hidden if the name is too long, you can hover over the tab and see the full title without having to click into it.

@over-soul commented on GitHub (Apr 14, 2020): Hi @ssddanbrown, I think it is important to show which book a chapter or page is from since you could have pages that have the same name open in tabs and you have to click through multiple tabs to find the page you are looking for. If the book name is in the title, while it might be hidden if the name is too long, you can hover over the tab and see the full title without having to click into it.
Author
Owner

@Mynster9361 commented on GitHub (Jan 23, 2021):

@over-soul
If you have not already found a solution for this you can do the following to get the wished result:

To change the dynamic title there needs to be created a new function of 'setPageTitel' that receives 2 arguments instead of one.
To do this we need to enter Controller.php

cd /var/www/bookstack/app/Http/Controllers
vim Controller.php

I called the new function 'setTitle' and added it right uder 'setPageTitle' in 'Controller.php'

/**
* Adds extended page title into the view.
*/
public function setTitle(string $content, string $book)
{
$title = $book.' | '.$content;
view()->share('pageTitle', $title);
}

Since it is an extended page title we need to change the controller for Page and Chapter since it is those that we would like to be extended titles

vim PageController.php

In this function this line is what needs to be changed since this is where it gets the 'book' and 'page' in the title
Alter this line from:
$this->setPageTitle($page->getShortName());
To:
$this->setTitle($page->getShortName(), $page->book->getShortName());

/**
* Display the specified page.
* If the page is not found via the slug the revisions are searched for a match.
* @throws NotFoundException
*/**
public function show(string $bookSlug, string $pageSlug)
{
try {
$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
} catch (NotFoundException $e) {
$page = $this->pageRepo->getByOldSlug($bookSlug, $pageSlug);

if ($page === null) {
throw $e;
}

return redirect($page->getUrl());
}

$this->checkOwnablePermission('page-view', $page);

$pageContent = (new PageContent($page));
$page->html = $pageContent->render();
$sidebarTree = (new BookContents($page->book))->getTree();
$pageNav = $pageContent->getNavigation($page->html);

// Check if page comments are enabled
$commentsEnabled = !setting('app-disable-comments');
if ($commentsEnabled) {
$page->load(['comments.createdBy']);
}

Views::add($page);
$this->setTitle($page->getShortName(), $page->book->getShortName());
return view('pages.show', [
'page' => $page,
'book' => $page->book,
'current' => $page,
'sidebarTree' => $sidebarTree,
'commentsEnabled' => $commentsEnabled,
'pageNav' => $pageNav
]);
}

vim ChapterController.php

In this function this line is what needs to be changed since this is where it gets the 'book' and 'chapter' in the title
Alter this line from:
$this->setPageTitle($chapter->getShortName());
To:
$this->setTitle($chapter->getShortName(), $chapter->book->getShortName());

/**
* Display the specified chapter.
*/
public function show(string $bookSlug, string $chapterSlug)
{
$chapter = $this->chapterRepo->getBySlug($bookSlug, $chapterSlug);
$this->checkOwnablePermission('chapter-view', $chapter);

$sidebarTree = (new BookContents($chapter->book))->getTree();
$pages = $chapter->getVisiblePages();
Views::add($chapter);
 
$this->setTitle($chapter->getShortName(), $chapter->book->getShortName());
return view('chapters.show', [
'book' => $chapter->book,
'chapter' => $chapter,
'current' => $chapter,
'sidebarTree' => $sidebarTree,
'pages' => $pages
]);
} # # #

Result can be seen in the discord:

https://discord.com/channels/578552496637739008/585101285112676392/802225898601971733

@Mynster9361 commented on GitHub (Jan 23, 2021): @over-soul If you have not already found a solution for this you can do the following to get the wished result: To change the dynamic title there needs to be created a new function of 'setPageTitel' that receives 2 arguments instead of one. To do this we need to enter Controller.php ``` cd /var/www/bookstack/app/Http/Controllers vim Controller.php ``` I called the new function 'setTitle' and added it right uder 'setPageTitle' in 'Controller.php' ``` /** * Adds extended page title into the view. */ public function setTitle(string $content, string $book) { $title = $book.' | '.$content; view()->share('pageTitle', $title); } ``` Since it is an extended page title we need to change the controller for Page and Chapter since it is those that we would like to be extended titles `vim PageController.php` In this function this line is what needs to be changed since this is where it gets the 'book' and 'page' in the title Alter this line from: $this->setPageTitle($page->getShortName()); To: $this->setTitle($page->getShortName(), $page->book->getShortName()); ``` /** * Display the specified page. * If the page is not found via the slug the revisions are searched for a match. * @throws NotFoundException */** public function show(string $bookSlug, string $pageSlug) { try { $page = $this->pageRepo->getBySlug($bookSlug, $pageSlug); } catch (NotFoundException $e) { $page = $this->pageRepo->getByOldSlug($bookSlug, $pageSlug); if ($page === null) { throw $e; } return redirect($page->getUrl()); } $this->checkOwnablePermission('page-view', $page); $pageContent = (new PageContent($page)); $page->html = $pageContent->render(); $sidebarTree = (new BookContents($page->book))->getTree(); $pageNav = $pageContent->getNavigation($page->html); // Check if page comments are enabled $commentsEnabled = !setting('app-disable-comments'); if ($commentsEnabled) { $page->load(['comments.createdBy']); } Views::add($page); $this->setTitle($page->getShortName(), $page->book->getShortName()); return view('pages.show', [ 'page' => $page, 'book' => $page->book, 'current' => $page, 'sidebarTree' => $sidebarTree, 'commentsEnabled' => $commentsEnabled, 'pageNav' => $pageNav ]); } ``` `vim ChapterController.php` In this function this line is what needs to be changed since this is where it gets the 'book' and 'chapter' in the title Alter this line from: $this->setPageTitle($chapter->getShortName()); To: $this->setTitle($chapter->getShortName(), $chapter->book->getShortName()); ``` /** * Display the specified chapter. */ public function show(string $bookSlug, string $chapterSlug) { $chapter = $this->chapterRepo->getBySlug($bookSlug, $chapterSlug); $this->checkOwnablePermission('chapter-view', $chapter); $sidebarTree = (new BookContents($chapter->book))->getTree(); $pages = $chapter->getVisiblePages(); Views::add($chapter); $this->setTitle($chapter->getShortName(), $chapter->book->getShortName()); return view('chapters.show', [ 'book' => $chapter->book, 'chapter' => $chapter, 'current' => $chapter, 'sidebarTree' => $sidebarTree, 'pages' => $pages ]); } # # # ``` Result can be seen in the discord: https://discord.com/channels/578552496637739008/585101285112676392/802225898601971733
Author
Owner

@ssddanbrown commented on GitHub (Jan 24, 2021):

Just a reminder that edits to core bookstack files are not supported and may cause trouble when attempting to update to newer releases.

@ssddanbrown commented on GitHub (Jan 24, 2021): Just a reminder that edits to core bookstack files are not supported and may cause trouble when attempting to update to newer releases.
Author
Owner

@bridgeyuwa commented on GitHub (Mar 4, 2021):

@over-soul

There is a tutorial in the link below on how to achieve that , but modifying bookstack to incorporate it is too much for my Laravel knowledge level

https://laravelarticle.com/dynamic-seo-meta-tags-in-laravel-website

@bridgeyuwa commented on GitHub (Mar 4, 2021): @over-soul There is a tutorial in the link below on how to achieve that , but modifying bookstack to incorporate it is too much for my Laravel knowledge level https://laravelarticle.com/dynamic-seo-meta-tags-in-laravel-website
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#1322