Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I use a custom post called "abschreibungstabelle".

For all posts, I want to set the meta title dynamically:

"This is a test: " & the post title

Is there any easy way to do this:

Actually I use the following snippet in my header:

<title>
        <?php if ( is_plugin_inactive('wordpress-seo/wp-seo.php') ) {
               bloginfo( 'name' );
              } ?> <?php wp_title("|", true); ?>
</title>

The result is "post title" | my blog

Thank you, cheers!

share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

I use something like this in my header.php:

<title> 
<?php 
    if(is_front_page())
        echo "Front Page Title";
    else if(is_404())
        echo "Page Not Found";
    else
        the_title();
    echo ' | '.get_bloginfo('name');  
?>
</title>

Check out Conditional Tags for more information.


As a Function() :

functions.php

function setTitle(){
    global $post;

    $title = get_the_title();
    $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );

    if(is_tax())
        $title = $term->name;
    else if(is_search())
        $title = "Search";
    else if(is_404())
        $title = "Page Not Found";


    if(is_singular('customCPT')){
        $terms = get_the_terms( $post->ID, 'customCPT' ); 
        $term = array_pop($terms);
        $title = $term->name.' '.$title;
    }

    echo $title.'  |  '.get_bloginfo('name');
}

Then in your header.php

<title><?php setTitle(); ?></title>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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