The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

How to write the "else" statement for If Function Exists for deactivated plugin? (2 posts)

  1. Dgold
    Posted 8 years ago #

    This question is based on the advice in the Codex here:

    I see how to do the "IF FUNCTION EXISTS". How do I add some kind of "ELSE IF FUNCTION DOES NOT EXIST Then Do This Other Thing Instead"?

    Here's my example. I'm using TTF Title Plugin to replace my post headlines with graphics. I set it up with "IF FUNCTION EXISTS" like this:

    <?php if (function_exists('the_ttftitle')) {  the_ttftitle($before="", $after="", $echo=true, $style="INSERT-YOUR-TTF-STYLE-HERE"); } ?>

    I would like to make it display regular-old php the_title(), if the_ttftitle() does not exist. (If the plugin is deactivated).

    Probably something with the word "else" but I don't know how to write it. Who can show me the code?

    Thanks Support Forum

  2. Dgold
    Posted 8 years ago #

    Got it! I figured it out by reading some PHP reference that came up in Google.

    Here's the way to do the if.... else.

    This is also (in my opinion) the best way to "do" the TTF Titles plugin

    <?php if (function_exists('the_ttftitle')) { the_ttftitle($before="", $after="", $echo=true, $style="YOUR-TTF-STYLE-HERE"); } else { the_title(); }?>

    This shows the fancy-font title *if* the plugin is turned on. It shows your regular text title, if the plugin is deactivated. Seems safer, degrades cleanly.

Topic Closed

This topic has been closed to new replies.

About this Topic