Use PHP to insert WP site name in a page

by JohnGG
5 replies
Hi,
Is it possible to put some PHP in the html of a WP page so that the site name is displayed. I have tried inserting <?php bloginfo('name'); ?> but did not get a result.

Any clues please?

Cheers

JohnGG
#html #insert #page #php #site
  • Profile picture of the author Mike P Smith
    That's normally how it's done.

    Where exactly are you placing that code? It may very well be that there is some code before that which is directing PHP to divert around that code.
    {{ DiscussionBoard.errors[2005956].message }}
  • Profile picture of the author Luke Graham
    Originally Posted by JohnGG View Post

    Hi,
    Is it possible to put some PHP in the html of a WP page so that the site name is displayed. I have tried inserting <?php bloginfo('name'); ?> but did not get a result.

    Any clues please?
    Where abouts are you trying to display the information?

    In most cases, you would use that inside the themes header.php - if you are trying to do that as the page title, you might want to check what the user is visiting - if its a post then display the post title, followed by the site name.
    Signature
    Best Ways To Make Money Online

    Eight bytes walk into a bar. The bartender asks, “Can I get you anything?”
    “Yeah,” reply the bytes. “Make us a double.”
    {{ DiscussionBoard.errors[2006042].message }}
    • Profile picture of the author JohnGG
      It seems I need a plugin such as the php-exec plugin to enable that. I want to put it in a page content, like TOS.

      Anyone used that plugin?

      JohnGG
      {{ DiscussionBoard.errors[2008486].message }}
      • Profile picture of the author Luke Graham
        Originally Posted by JohnGG View Post

        It seems I need a plugin such as the php-exec plugin to enable that. I want to put it in a page content, like TOS.

        Anyone used that plugin?
        You dont need any plugins.....

        If you change your themes header.php (if it has one) you do not need any plugins; it should be included in all templages (pages, posts, archives) and you can change the output with somethnig like (untested code, just as an example);


        PHP Code:
          <?php if ( is_home() )   { bloginfo('name'); } 
          elseif ( 
        is_search() )   { bloginfo('name'); print " | Your search results tags "; } 
          elseif ( 
        is_single() )   { wp_title(''); print " | "bloginfo('name'); } 
          elseif ( 
        is_page() )     { bloginfo('name'); print " | "wp_title(''); }
          elseif ( 
        is_category() ) { bloginfo('name'); } ?>
        ....and so on.

        Conditional Tags WordPress Codex
        Signature
        Best Ways To Make Money Online

        Eight bytes walk into a bar. The bartender asks, “Can I get you anything?”
        “Yeah,” reply the bytes. “Make us a double.”
        {{ DiscussionBoard.errors[2009498].message }}
  • Profile picture of the author stma
    Just add it to your theme (in the loop of singlepage.php) and it will display. Just won't work in a post with out a plugin -- then it probably still won't work half the time
    {{ DiscussionBoard.errors[2009098].message }}

Trending Topics