Add PHP code before any other code in Wordpress template, on a per post basis -
Add PHP code before any other code in Wordpress template, on a per post basis -
i'm trying figure out how add together php code template, before else (line:1).
i want using custom field in post itself. i'm experimenting wordpress hooks, can seem able insert html/js, , within actual header.php, , not before it.
is there specific hook should utilize this, , also, possible add together php template in manner?
if need access custom fields of post, need hook wp
hook fires after post object created , conditional functions available, before get_header
fired. in functions.php file:
<?php function my_function(){ global $post; if( is_single() ){ $my_meta = get_post_meta( $post->id, 'my key', true ); // assumes custom meta returns single value if( 'value expected' == $my_meta ){ // php code run goes here } } } add_action( 'wp', 'my_function' );
php wordpress themes
Comments
Post a Comment