Answer the question
In order to leave comments, you need to log in
How to replace content depending on Wordpress category?
Hello!
function routeCard_shortcode($atts) {
extract(shortcode_atts(array( 'post_id' => '' ), $atts)); $output="";
if ( empty($post_id) ) { $output.= "(_*_)"; } else { $output.= "Post Id: ".$post_id; }
return $output;
}
add_shortcode('routeCard', 'routeCard_shortcode');
function routeCard_content( $data ){
$cat = get_category_by_slug( 'routes' ); $id = $cat->term_id;
if (in_array($id, $data['post_category'])) { $data['post_content'] = "[routeCard]";}
return $data;
}
add_filter( 'wp_insert_post_data' , 'routeCard_content' , 99 );
Answer the question
In order to leave comments, you need to log in
The_content hook is suitable for you, you can also check if the post belongs to a certain category
add_filter( 'the_content', 'my_content' );
function my_content( $content ) {
// проверяем, что у записи нет контента
if ( strlen($content) == 0 ) {
return 'new content';
}
return $content;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question