Archived topic
Attachment page
9 replies · Started by Marco on March 6, 2019
Hello
1. How do I replace the page title with e.g. the name of the parent page - couldn’t find a filter to replace the page-title?
2. Where do I set which picture size to show on the attachment page - for some reason it is a 720-300px image which is not wide enough.
3. How do I remove the comment form on the attachment page only?
Thank you in advance for your input.
Hi there,
1. I'm not sure if there's a filter for the page title, unfortunately. You would likely need to create an attachment.php template file in your child theme. Then you can replace the_title() with the necessary function to grab the parent page title.
2. Something like this might do it: https://gist.github.com/rfmeier/5753101
3. This plugin should do it: https://wordpress.org/plugins/disable-comments/
Thanks for your input
1. as to creating an attachment.php template file, I guess I can just copy the single.php file from the GP theme? - to bad there is no filter to manipulate the page title - was wondering whether you would consider adding a filter in one of your next versions.
the custom template file only seems to work if the file is in the main child theme folder - is there a way to put those templates into a sub-folder?
2. that code worked
3. found the following filter that seems to work:
/* Comment Form: Remove comment form from attachment page
---------------------------------------------------------------------------- */
function themeprefix_remove_attachment_comments( $open, $post_id ) {
//return false;
$post = get_post( $post_id );
if ( $post->post_type == 'attachment' )
$open = false;
return $open;
}
add_filter( 'comments_open', 'themeprefix_remove_attachment_comments', 10, 2 );
1. the_title() is filterable by default, but it applies to a bunch of elements throughout WordPress (menu items, widget titles etc..).
Yes, I would copy single.php, and you'll likely need to merge content-single.php in place of the get_template_part() function in there, as I think that file contains the_title().
3. Nice! Thanks for sharing :)
hi Tom,
I've just set up the theme and this is my first post. I really like the clean, basic and neutral front end which will allow my artwork to stand out.
I also want to create an attachment.php template file dedicated for images and will copy
single.php for this purpose.
When you say "you’ll likely need to merge content-single.php in place of the get_template_part() function.." does this mean I add all the code that's contained in content-single.php directly into single.php deleting and replacing the current code of:
get_template_part( 'content', 'single' );
thanks!
Exactly :)
hi Tom,
Unfortunately this didn't work and resulted in the white screen.
In place of get_template_part( 'content', 'single' ); I tried the following:
1) The entire code from content-single
2) All code from content-single within <article> tag, including this tag
3) All code from content-single within <div class="inside-article"> tag, including this tag
4) All code from content-single within <div class="inside-article"> tag, excluding this tag.
Tried this with a file named attachment.php in both Child theme and Parent folder
Could you possibly set up an attachment page at your end to send across? At the moment I'm guessing a bit here.
Thanks,
Give this a shot: https://gist.github.com/generatepress/4e033b8e30efce6cffc07fe34cb2ac58
Let me know :)
Thanks that did the trick!
But it is only missing the image so I went into the WP TwentyNineteen theme file for attachments and copied below code and placed it into <div class="entry-content"> of my new attachments.php file:
<figure>
<?php
/**
* Filter the default twentynineteen image attachment size.
*
* @since Twenty Sixteen 1.0
*
* @param string $image_size Image size. Default 'large'.
*/
$image_size = apply_filters( 'twentynineteen_attachment_size', 'medium' );
echo wp_get_attachment_image( get_the_ID(), $image_size );
?>
</figure>
This works and I can even change the image size but I am concerned it is not GeneratePress code. How can it apply this filter correctly. Should I change anything here or leave it?
thanks
You can just leave it, as you can change the size directly without the need for a filter.