admin管理员组

文章数量:1415119

I have this command that I'm using. I want it to use the template formating for the title but I can't figure out how to add it. I found this code online to strip everything and I added <?php wp_title(); ?> which shows the title but in plain text. How can I add it to match the rest of the site? smdpphiladelphia

<?php
/**
 * Template Name: Clean Page
 * This template will only display the content you entered in the page editor
 */
?>
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
    <meta charset="<?php bloginfo( 'charset' ); ?>">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <?php wp_head(); ?>

</head>
<body>
<?php wp_title(); ?>
<?php
    while ( have_posts() ) : the_post();  
        the_content();
    endwhile;
?>
<?php wp_footer(); ?>
</body>
</html>

I have this command that I'm using. I want it to use the template formating for the title but I can't figure out how to add it. I found this code online to strip everything and I added <?php wp_title(); ?> which shows the title but in plain text. How can I add it to match the rest of the site? smdpphiladelphia

<?php
/**
 * Template Name: Clean Page
 * This template will only display the content you entered in the page editor
 */
?>
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
    <meta charset="<?php bloginfo( 'charset' ); ?>">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <?php wp_head(); ?>

</head>
<body>
<?php wp_title(); ?>
<?php
    while ( have_posts() ) : the_post();  
        the_content();
    endwhile;
?>
<?php wp_footer(); ?>
</body>
</html>
Share Improve this question asked Aug 23, 2019 at 22:21 James E AndrewsJames E Andrews 1
Add a comment  | 

2 Answers 2

Reset to default 0

Basically, if I understand your question properly, you will want to look for another file named "header.php" (or "page-{something}-header.php" for a special header that only applies to a specific page type), which represents what is output by wp-head() (shown in your code).

If you open header.php, you should find something like the following:

<head>
     <title> <?php wp_title(); ?></title>
...

Keep in mind, this can get really complex. There are many themes with several conditional statements to modify your page title for any of several different circumstances. See the following example of how complex a fairly simple theme can make it.

<?php
if (function_exists('is_tag') && is_tag()) {    
    echo 'Tag Archive for &quot;'.$tag.'&quot; - ';    
} elseif (is_archive()) {    
    wp_title(''); echo ' Archive - ';    
} elseif (is_search()) {    
    echo 'Search for &quot;'.wp_specialchars($s).'&quot; - ';    
} elseif ( (!(is_404()) && (is_single()) || (is_page()) ) && !(is_front_page()) ) {    
    wp_title(''); echo ' | ';    
} elseif (is_404()) {    
    echo 'Not Found - ';    
}
bloginfo('name');
?>
</title>

If you already like your theme, but just want to customize how the page titles are drawn, you may want to review this brief tutorial for a better way to update page titles throughout your site, using add_filter('document_title_parts','your_customizing_function') (documentation for document_title_parts).

I just figured out I could make it a lot easier by simpling adding teh custom attribute into the header code like so <h1 class="resurrect-entry-title resurrect-main-title">

本文标签: wp titleAssistance with wptitle function