Removing code from Image Attachment Pages
-
Hi Stella,
For this you would create a custom template for your attachment page. You can create a child theme of Portfolio Press, and add a custom attachment.php file to your theme.
Here’s an explanation of how the WordPress template hierarhcy works: https://developer.ww.wp.xz.cn/themes/basics/template-hierarchy/
Here’s more about creating a child theme: https://developer.ww.wp.xz.cn/themes/advanced-topics/child-themes/
In that php template file, you can adjust your attachment page to display whatever information you want (and also remove comments).
The Portfolio Press theme should have an index.php file that you can use as the basis for your attachment.php file.
Hi ancawonka,
Thank you for this info. I shall have a go.
Stella
Hi ancawonka,
I’ve tried to do this but I really don’t know enough about web design and it’s complicated. But thank you anyway.
Stella16
I can imagine how accomplishing everything ancawonka suggested would be overwhelming and confusing. Unfortunately, what’s suggested is the proper approach. There is another approach that’s a bit “dirty”. Going with the images linked to the attachment page approach, but instead of making a new template, you could try just hiding the undesirable content with CSS.
You need a safe place for your custom CSS. If you got as far as creating a child theme, the new CSS can be placed in the child’s style.css file. Some themes have a place in settings for custom CSS, you could use this if it exists. There is also a custom CSS plugin that allows you to safely add CSS without editing code files.
Determining the right CSS can be a challenge as well. You need to use your browser’s developer tools to help with this. It’ll have an element selector tool where you can select any element on a page and the applicable CSS is displayed. You can add new rules to this tool and the rules are applied immediately, but only until the page is reloaded. For added rules to be permanent, they must be added as previously mentioned. Still, the tool is great for trial and error coding. Try different things until you find what works, then copy the rule to a permanent location.
The general format for CSS that hides something is like this:
.selector { display: none; }The key is finding the right selector. That is where the developer tool is a big help, but having a knowledge of how CSS selectors work is important. If you click on an element in the style editor tool, then add a rule on the CSS side, the tool usually suggests a likely selector that could work. If you get stuck on hiding a particular element, post a live link to the page in question and someone here should be able to help you out.
Hi bcworkz,
Thank you so much for your reply. I will see if I succeed over the weekend.
Stella16
The topic ‘Removing code from Image Attachment Pages’ is closed to new replies.
(@stella16)
9 years, 4 months ago
Hi,
I am using the Portfolio Press theme (2.7.2) by Devin Price. I have a problem on my site with Image Attachment pages. I have galleries of images on my home page and on products page. When customers click on those images, I don’t want them to go directly to the Image file, as I want to put some text in to enable them to be able to click back to the page they were on, and I don’t seem to be able to do this.
However, the other option is to have customers to click and be sent through to the image Attachment Page, which is good because I can put text about the image and get them to click through to another page.
The bad thing about it is that there is text (on all the attachment pages) saying:
Published at 1000 × 767 in Wooden Image Blocks
and
Leave a Reply
Logged in as Stella 3. Log out?
Comment
There is then a box for a comment to be put and to post it. I really want to remove these pieces of text but don’t know what piece of coding to alter. I have looked in my dashboard at the ‘comments’ and ‘discussion’ settings, but there is nothing there to switch off comments. I have looked at the editor sections of coding but am completely lost.
You can see an example here:
http://www.madaboutwood.co.uk/sample-page/web-9/
I really would be grateful for any help.
Thank you
Stella16