[wp-trac] [WordPress Trac] #10275: Filter logic has been put into the template loader while it not belongs there.

WordPress Trac noreply at wordpress.org
Tue Jan 7 17:51:06 UTC 2025


#10275: Filter logic has been put into the template loader while it not belongs
there.
-------------------------------------------------+-------------------------
 Reporter:  hakre                                |       Owner:  (none)
     Type:  defect (bug)                         |      Status:  reviewing
 Priority:  normal                               |   Milestone:  6.8
Component:  Themes                               |     Version:  2.8
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch needs-testing has-         |     Focuses:  template
  testing-info close                             |
-------------------------------------------------+-------------------------

Comment (by sppramodh):

 Sure, Please find the shortcode, i used for testing

 {{{
 function display_attachment_by_id( $atts ) {
     $atts = shortcode_atts( array(
         'id' => 0,
     ), $atts, 'attachment_id' );

     $attachment_id = intval( $atts['id'] );

     // Check if a valid attachment ID is provided
     if ( $attachment_id <= 0 ) {
         return 'Invalid attachment ID.';
     }

     // Get the attachment HTML markup (image, file link, etc.)
     $attachment_html = wp_get_attachment_link( $attachment_id );

     // If attachment is found, return the HTML, otherwise return a message
     return $attachment_html ? $attachment_html : 'Attachment not found.';
 }

 add_shortcode( 'attachment_id', 'display_attachment_by_id' );
 }}}


 Usage:

 {{{
 [attachment_id id="12"]
 }}}

 Let me know if further details or additional tests are needed!

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/10275#comment:17>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list