0

How can I echo multiple tasks if a common WordPress function exists.

For example, I want to reduce the following:

<?php if (function_exists ('pluginName')) echo someName (1); ?>
<?php if (function_exists ('pluginName')) echo someName (2); ?>
<?php if (function_exists ('pluginName')) echo someName (3); ?>
<?php if (function_exists ('pluginName')) echo someName (4); ?>

into a single query like this:

<?php if (function_exists ('pluginName')) echo someName (1); someName (2); someName (3); someName (4); ?>

What is the right way to do it?

4
  • 1
    Brackets may help. See second example - the one with multiple statements. – Howdy_McGee May 11 '16 at 18:17
  • Something like this? -> <?php if (function_exists ('pluginName')) { echo someName (7); echo someName (8); echo someName (9); } ?> – AndrewL64 May 11 '16 at 18:21
  • 1
    Yup, that'll do it. – Howdy_McGee May 11 '16 at 18:21
  • Thank you good sir. Do add that as the answer and I'll mark it as correct. – AndrewL64 May 11 '16 at 18:23
0

As @Howdy_McGee mentioned in the comments, you can just wrapped the multiple commands you want to run within curly brackets like this:

<?php if (function_exists ('pluginName')) { echo someName (7); echo someName (8); echo someName (9); } ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.