• Resolved stanu5

    (@stanu5)


    Hi,

    I am new to WordPress and PHP but have a lot of experience with ASP. I seemed to be stuck on the simplest thing but can’t see what I am doing wrong.

    I am trying to change the layout based on the page that is being displayed. For example I created “About” page through WordPress Admin Pannel and now am trying to get the following code to work. For some (unknown to me) reason the code does not like the condition in my if statement.

    <?php
    $pagetitle = wp_title(‘ ‘, false);
    if ($pagetitle == “About”) :
    ?>

    …code…

    <?php endif; ?>

    Please help.

    Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • If you are putting your code in the content area of a Page or post – that will not work, unless you use a plugin like phpexec, execphp and some similar plugins.
    If we want a different layout for a Page – we ususally go by creating a new Page template and create the new Page by using that template.
    See more: https://codex.www.ads-software.com/Pages#Page_Templates

    Thread Starter stanu5

    (@stanu5)

    Hi Moshu,

    Thank you for your response. I am actually creating it within the page template and not in the content area. For some reason the condition within the if statement is not recognized properly. For example if I change it to if ($pagetitle != “About”) it steps into the if loop for every page including my “About” page. When I try to put the echo inside the if it prints the titles correctly. For my “About” page it in fact prints the word About. I really can’t figure out why it doesn’t work.

    Thanks in advance for any ideas.

    Hmm… Maybe this is what you need: https://codex.www.ads-software.com/Conditional_Tags

    Thread Starter stanu5

    (@stanu5)

    This worked perfectly!!! THANK YOU VERY MUCH!!!

    (I am still confused though why my other code is incorrect :))

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘wp_title help’ is closed to new replies.