Tag Info

New answers tagged

0

You can try this code to add the new attribute in the html code: $dom = new DOMDocument(); $dom->loadHTML($html); foreach ($dom->getElementsByTagName('a') as $item) { $item->setAttribute('data-caption', 'This is an anchor tag'); echo $dom->saveHTML(); exit; }


0

There is also a straightforward CSS solution to override WordPress’s inline styling. .wp-caption { display: table-cell; width: auto !important; } Setting the width to auto on a block element would result in its width expanding to fill the available space, which is probably not what is wanted, but setting display: table-cell causes the div to ...


0

It's more a programming question, but try this: $post = get_post( get_post_thumbnail_id() ); if ( !isset( $post->post_title ) ) { echo 'Sorry no title'; } else { echo $post->post_title; }


0

Use if statements. if($caption = get_post(get_post_thumbnail_id())->post_excerpt){ echo $caption; }else{ //echo something else }



Top 50 recent answers are included