Quantcast
Channel: Syntax for conditional statement in Wordpress functions.php - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Answer by Benz1 for Syntax for conditional statement in Wordpress functions.php

$
0
0

Thanks Andrew. After much Googling and trial & error, I've come up with the following. I don't think it's a very elegant solution or even if the syntax is completely correct but it seems to work:

function custom_event($content) {    global $post;    if( get_field( "date" ) != "" || get_field( "time" ) != "" || get_field( "location" ) != "" ){         $open = "&#0091;";    }    if( get_field( "date" ) != ""){        $ondate = 'On '.get_field( "date" );    }    if( get_field( "time" ) != ""){        $attime = 'at '.get_field( "time" );    }    if( get_field( "location" ) != ""){        $atlocation = 'at '.get_field( "location" );    }    if( get_field( "date" ) != "" || get_field( "time" ) != "" || get_field( "location" ) != "" ){         $close = "&#0093; ";    }    if( in_category( 'events', $post ) ) {        $beforecontent = "<strong>$open$ondate $attime $atlocation$close</strong><br><br>";        $fullcontent = $beforecontent . $content;        return $fullcontent;    }    return $content;}add_filter('the_content', 'custom_event');

Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>