Skip to content Skip to sidebar Skip to footer

How To Comment Out Both Html And Php In Php Inside Html?

Here is a line of code that I want to comment out,

Solution 1:

<!--    <h1 class="post_title">
<a href="<?php// the_permalink();?>" title="<?php the_title_attribute(); ?>">
<?php// the_title(); ?></a>
</h1>
-->

This will comments only HTML portion, where as you'll find rendered PHP code in view source of webpage..

better way..

<?php/*    <h1 class="post_title">
    <a href="<?php // the_permalink();?>" title="<?php //the_title_attribute(); ?>">
    <?php // the_title(); ?></a>
    </h1>
    */?>

Solution 2:

try this

<?php/*
 * <h1 class="post_title"><a href="<?php the_permalink();?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1>
 */?>

Solution 3:

There is the HTML way...

<!-- commented out stuff -->

...and there is the PHP way...

// for rows only/* for
   multiple
   rows */$or = /* for inline */'sections';

The difference between the 2 is that while the HTML way will still render the code on the page (can view using 'view source' in the browser), the PHP way will prevent it from being viewed by the outside world, ie. only you or other fellow programmers allowed to see the actual files will see the commented out pieces.

Solution 4:

For that functionality you would have to refactor your code.

<?php//print('<h1 class="post_title"><a href="'. the_permalink() . '" title="' . the_title_attribute() . '">' . the_title() . '</a></h1>');?>

If all your code is within PHP then commenting out some of it becomes an easy thing, you would simply use PHP's commenting rules.

Solution 5:

If you want to print only the result from php functions. I hope this should help you.

<?$var = //"<h1 class='post_title'><a href="."'php the_permalink()' ".
    //"  title="."'php the_title_attribute() ' ".
    //">"."'php the_title()' ".
    //"' </a></h1>";echo$var;
?>

or

<?$var = /*"<h1 class='post_title'>.*//*"<a href='".*/"'php the_permalink()' "./*"  title=".*/"'php the_title_attribute() ' "./*">".*/"'php the_title()' ".
        /*"</a>".
    "</h1>"*/;


echo$var;
    ?>

Post a Comment for "How To Comment Out Both Html And Php In Php Inside Html?"