php - My post falls between two If statements, what can I do? -
currently i'm trying filter out various things meta portion of wordpress website, , i've found issue, using following code working until needed bit more specific.
if (is_singular('post')) { $title = get_the_title (); print '<title>'.$title.'</title>'; $feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->id) ); print '<meta property="og:image" content="'.$feat_image.'"/>'; print '<meta name="description" content="" />'; } else { print '<title></title>'; print '<meta name="description" content="" />'; }
note edited meta descriptions above they're empty, sake of posting on stack.
then wanted start filtering based on tags post has, , going conflict declared (is_singular('post'))
function above.
however, used code below.
if ( has_tag( 'spanish' )) { print '<title>'.$title.'</title>'; $feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->id) ); print '<meta property="og:image" content="'.$feat_image.'"/>'; print '<meta name="description" content="" />'; }
and displaying meta portion in category wish too, how ever it's displaying meta description other function well, can stack?
this might sound simplistic, firstly want document want happen. maybe make flow chart or write couple of paragraphs. either way, need know non-code point of view first. enable answer questions "does tag take precedence on single post?" once know process, move conditions away output simplify process. this:
// defaults $title = '...'; $metadescription = '...'; $featuredimage = '...'; // overrides difference scenarios if (is_singular('post')) { // set title, etc here } if (has_tag('spanish')) { // override or concatenate title, etc here } // output print "<title>$title</title>"; <!-- etc etc -->
Comments
Post a Comment