wordpress - WP: Change footer.php from within loop -


this question wordpress. have custom meta in post. need able change footer (add specific logos - s) depending on meta tag present in post. logic clear me.

the question how reach footer.php within loop. or need make in footer.php ? problem can not deal footer content through js because footer not present on page when loop happening.

you can pull meta anywhere in theme; outside loop. header, footer, etc. pass get_the_id() first parameter of get_post_meta().

get_the_id() retrieves id of post/page being viewed.

example:

<?php $logo_meta = get_post_meta( get_the_id(), 'metafieldname', true ); ?>  <?php if ($logo_meta) echo $logo_meta; ?> 

to make simpler:

<?php echo get_post_meta( get_the_id(), 'mymetafieldname', true ); ?> 

or assuming storing src of logo image (url) meta value, trick:

<?php $logo_image_src = get_post_meta( get_the_id(), 'mymetafieldname', true ); if ($logo_image_src)     echo '<img src="'.$logo_image_src.'" alt="thelogoalttag" />; ?> 

also, depending on whether item uploaded via wp media library, store id of media item in post meta , retrieve image src via wp_get_attachment_image_src().


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -