2

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

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

A popular way to comment it out would be to comment out the html and php separately.

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

Is there a better way to do this?

3
  • Just used <?php /*?> before code and used <?php */?> after your code. Commented Oct 13, 2014 at 6:49
  • Use Suppr, definitely the best way to comment out some code. Commented Oct 13, 2014 at 6:53
  • Why am I getting a downvote for the question? Seems like an obvious question to me. Commented Oct 13, 2014 at 7:20

5 Answers 5

4
<!--    <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>
    */ ?>
Sign up to request clarification or add additional context in comments.

Comments

2

try this

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

Comments

0

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.

Comments

0

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.

Comments

0

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;
    ?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.