最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

the content - does wp function the_content(); accept another tag inside

programmeradmin5浏览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>';
} 
); ?>

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>';
} 
); ?>
Share Improve this question asked Apr 13, 2020 at 21:05 DragutDragut 1732 gold badges2 silver badges11 bronze badges 2
  • 2 as you can see, the_content() accepts the 'read more link' text and a boolean 'stripteaser' argument... it does not accept any html tags. developer.wordpress/reference/functions/the_content - you could however use a filter function to append anything after or before or inside the content developer.wordpress/reference/hooks/the_content – Michael Commented Apr 13, 2020 at 22:09
  • I'll look at it, thanks! – Dragut Commented Apr 15, 2020 at 13:11
Add a comment  | 

1 Answer 1

Reset to default 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.

发布评论

评论列表(0)

  1. 暂无评论