5

I want to add some php and html code in my page but i can't do it using Visual Composer, i can choose the "Raw Html" Box but that doesn't render PHP at all, only HTML.

Do you guys have any idea how can i do it?? Or is there a workaround solution?

6
  • 3
    You should not be adding PHP code in text editors. It is extremely unsafe. Create a shortcode Apr 13, 2016 at 16:54
  • Will a shortcode make me able to add a file like : (Dummy example) <h2>Hello</h2> <?php Echo "another hello"; ?> Apr 13, 2016 at 16:58
  • 3
    Yes, check the shortcode API. Just remember, shortcodes should return, not echo Apr 13, 2016 at 17:01
  • I'll test right now and be back for a feedback Apr 13, 2016 at 17:01
  • 1
    Test worked, Thanx Man Appreciate it (y) Apr 13, 2016 at 17:56

1 Answer 1

13

So i found the answer with the help of Pieter Goosen and i would like to share it with you:

A good method will be to create a Shortcode.

To do it, just go to your template Functions.php file and create your function like this example:

function shortcode_hello( $atts ){
  $time = ( date('G') < 9 ) ? "good morning" : "good day";
    return "Hello, and " . $time . ', my name is Linda';
}
add_shortcode( 'hello', 'shortcode_hello' );

Now all you have to do is to place the [hello] shortcode on your page builder (Visual composer here).

1
  • 1
    Tell your boss that Visual Composer is the cancer of WordPress. Tell your boss that you've separated content concerns from visual one, and that you're not tied into an abhorrent shortcode nightmare should you ever wish to move away from VC and/or change the layout. [ wordpress.stackexchange.com/questions/230804/… ]
    – prosti
    Nov 28, 2016 at 18:55

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