0

On mobile, I want to display what page my users are on. I have 6 top pages at the moment.
Home, Projects, Blog, Contact, Privacy Policy and Impressum. Both Projects and Blog have posts in them. Projects is a custom post type as well.
When a user clicks on Contact, title should change to contact. If they go to Project and click on a post, the title should say projects. I hope I make it clear.
I don't mind working with if statements either if that's a solution.

Here is an image of what it would look like:
enter image description here

I hope I am making myself clear. Does anyone have a solution?

I have tried it with get_the_title() to echo the title, but this does not give me proper results. When I'm on my Contact Page, it does say Contact. But once I'm on my home, project or blog page, it gives me the title of some post item, and not the title of the page as I want.

To give more context of what I want:
Imagine it like a breadcrumb, but instead, I only want one part of it. So instead of
Home > Contact or Home > Project > Some Post Title I want only "Contact" or "Project". How would I go about that?


So now I have this code:

if ( is_front_page() ) {
         echo "Startseite";
     } elseif ( is_singular("blog") ) {
         echo "Blog";
     } elseif ( is_singular("project") ) {
         echo "Projekt";
     } elseif ( get_the_title() == "Datenschutz" ) {
         echo "Datenschutz";
     } elseif ( get_the_title() == "Impressum" ) {
         echo "Impressum";
     } elseif ( get_the_title() == "Contact" ) {
         echo "Kontakt";
     } elseif ( get_the_title() == "Blog" ) {
         echo "Blog";
     } elseif ( get_the_title() == "project" ) {
         echo "Projekte";
     }

Which almost works. The only Problem I am having is, when I'm on the Project and Blog page, where you can select a post. It doesn't show "Projekte" or "Blog".
When I'm clicking on a Project Post, it shows "Projekte". But when I'm on a Blog Post, it does not show "Blog".

Any ideas on how to fix that?

3
  • get_the_title() function will retrieve the current post title.Please check and let me know is that work? Oct 15, 2020 at 12:55
  • The problem with that, it will give me the Post Title, but when viewing any post I want the Page title. Oct 16, 2020 at 10:32
  • The only Problem I am having is, when I'm on the Project and Blog page, where you can select a post. It doesn't show "Projekte" or "Blog". so what is the exactly unexpected page displayed?
    – RachC
    Oct 17, 2020 at 1:44

1 Answer 1

0

After many attempts and help from others, I finally got a solution to my problem. That's the code I used:

<?php 

      
     if ( is_front_page() ) {
         echo "Startseite";
     } elseif ( is_singular("project") ) {
         echo "Projekte";
     } elseif ( get_the_title() == "Datenschutz" ) {
         echo "Datenschutz";
     } elseif ( get_the_title() == "Impressum" ) {
         echo "Impressum";
     } elseif ( get_the_title() == "Contact" ) {
         echo "Kontakt";
     } elseif ( get_post_type() == "project" ) {
         echo "Projekte";
     } elseif ( is_single() || is_home() ) {
         echo "Blog";
     }
      
  ?> 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.