0

I want to place some other PHP tag inside the_content() is it possible somehow?

<?php the_content(

$custom_attach = get_post_meta( $post->ID, 'wp_custom_attachment', true );

      $custom_attach = get_post_meta( get_the_ID(), 'wp_custom_attachment', true );

     $name = 'button';

if ( ! empty( $custom_attach ) ) {

    echo '<span class="icon-download">';
    echo '<a href="'.$custom_attach['url'].'">'.$name.'</a>';
    echo '<span>';
} 
); ?>
2

1 Answer 1

1

Why do you want to put your code between the braces in the_content()? What are you trying to accomplish?

Maybe this solves your problem?

<?php
    $custom_attach = get_post_meta( get_the_ID(), 'wp_custom_attachment', true );
    $name = 'button';

    if(!empty($custom_attach)) {
        echo '<span class="icon-download">';
        echo '<a href="'.$custom_attach['url'].'">'.$name.'</a>';
        echo '<span>';
    }

    the_content();
?>

This echoes the <span> -element with the class icon-download first, and then the content of the post.

3
  • I've a custom link, it is just for my registered users. I want to only users registered see my content and custom meta box content. Thanks your answer I'll try it. Can we add here like so '<a href="'.$custom_attach['url'].'">button</a>'; text instead variable '.$name.'
    – Dragut
    Commented Apr 14, 2020 at 6:09
  • Well, this answer should do what you want, as far as I can tell. As for replacing the .$name. part with button; Absolutely. No problem.
    – User
    Commented Apr 14, 2020 at 11:06
  • Unfortunately this doesn't work, because custom meta is out of () brackets
    – Dragut
    Commented Apr 15, 2020 at 13:10

Your Answer

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

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