1

I have a page and attachment addes to this page. Now I can output the content of this page with modified link attachment, when each attachment link otput title size and type of attachment like this <a href="name of file">Name attachment ( 456kB, *.pdf)</a>

I want todo this without plugin. Attachment I add in backend edit page with upload file. No use plugin. On frontend I use child Underscore + Understrap child theme. And I use classic editor in backend. No builder using.

<?php
/**
 * Partial template for content in page.php
 *
 * @package Understrap
 */

// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
?>

<article <?php post_class(); ?> id="post-<?php the_ID(); ?>">

    <?php
    if ( ! is_page_template( 'page-templates/no-title.php' ) ) {
        the_title(
            '<header class="entry-header"><h1 class="entry-title">',
            '</h1></header><!-- .entry-header -->'
        );
    }

    echo get_the_post_thumbnail( $post->ID, 'large' );
    ?>

    <div class="entry-content">

        <?php
        the_content();
        understrap_link_pages();
        ?>

    </div><!-- .entry-content -->

    <footer class="entry-footer">

        <?php understrap_edit_post_link(); ?>

    </footer><!-- .entry-footer -->

</article><!-- #post-<?php the_ID(); ?> --> 

I try to do it by add filter in wp_get_attachment_links do not modify output for attachment links but this is not good way

4
  • Can you explain more how you inserted the attachment using WP inbuilt media blocks or using any plugin or some other thing. Also share the snippet of template which rendering the frontend part because without knowing source code and the way attachment inserted into the post/page it is difficult to answer. Commented Mar 26 at 11:32
  • I added to question more details.
    – mardon
    Commented Mar 26 at 11:42
  • you can link to your previous question for context, someone trying to answer this would need to know where the attachment links are being shown which isn't mentioned in this question, the existence of the filter you asked about previously is super helpful information, though there's probably more context that would lead to a better solution if you provide some background for why you're inserting links to attachments and why they need this information added. E.g. if you're doing this to implement a download page or provide assets there are better ways
    – Tom J Nowell
    Commented Mar 26 at 13:46
  • @TomJNowell I add link to previous question with my try to solve this problem
    – mardon
    Commented Mar 26 at 15:12

0

Your Answer

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

Browse other questions tagged or ask your own question.