0

I have a hook, that detects opening the post(publication):

add_action('the_post', 'post_callback');

function post_callback($post) {
   $post->post_title = "New title";
   $post->post_content = "New content";
}

It replaces post_title, $post->post_content data on the custom values.

How to change HTML meta data on the page(title, description) inside function: post_callback?

1

2 Answers 2

0

Try this:

New title

add_filter('wp_title', 'filter_posttitle');
function filter_posttitle($title) {
 $title = 'New title '.$title;
 return $title;
}

and new content add code in header.php

<?php if ( is_single() ) { ?>
    <meta name="description" content="" />
<?php } ?>
0

Try this:

add_filter('the_title', 'new_title', 10, 2);
function new_title($title, $id) {
    if('custom_version' == get_post_type($id))
        $title = 'New title '; 
    return $title;
}

and new content

add_filter( 'the_content', 'new_content' ); 
function new_content( $content ) { 
    if ( is_singular('post')) {
        $content = 'New content';
        }
    return $content;
}
1
  • It replace title and content, but I need to replace title, description meta tags
    – Oleg
    May 1, 2017 at 17:10

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.