1

i have multiple tags and want to create multiple single.php for everyone tag.

How create single.php for tags??

This code working well for category, how to edit it for tags??

 function my_category_templates($single_template) {
 global $post;

 if ( in_category( 'raspee' )) {
    $single_template = dirname( __FILE__ ) . '/single-raspee.php';
 }
  return $single_template;
 }
 add_filter( "single_template", "my_category_templates" );
  • has_tag('tag_name') – ngearing Jul 25 '16 at 23:50
  • Thanx its working – FRQ6692 Jul 26 '16 at 0:00
  • Excellent I have posted an answer with this information. – ngearing Jul 26 '16 at 0:13
2

has_tag() is a function that will check if a post has a certain tag

You could integrate it into your code like so:

function my_category_templates($single_template) {
 global $post;

 if ( in_category( 'raspee' )) {
    $single_template = dirname( __FILE__ ) . '/single-raspee.php';
 }

 if ( has_tag( 'everyone' )) {
    $single_template = dirname( __FILE__ ) . '/single-everyone.php';
 }

  return $single_template;
 }
 add_filter( "single_template", "my_category_templates" );

you can check out this function here: https://developer.wordpress.org/reference/functions/has_tag/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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