attachment.php
is not the only template file for attachment display. mime-type based template files get priority.
- MIME_type.php – it can be any MIME type (image.php, video.php,
application.php). For text/plain, in order:
- text.php
- plain.php
- text_plain.php
http://codex.wordpress.org/Template_Hierarchy#Attachment_display
I expect that that is the issue you are seeing. Check your theme for image.php
.
There is a further problem with your code. Attachments don’t have categories as far as I know. The category is inherited from the parent post. That means that you will need to pass the parent post ID to in_category
.
if ( in_category('2', $post->post_parent) ) {
get_template_part('bet-photo');
}
I would also suggest get_template_part
, as in my version of the code, instead of PHP’s include
.
Related Posts:
- To close or not to close php
- How does printf( __( ) ); work?
- Return HTML Template Page with PHP Function
- Why do templates contain so many PHP tag pairs?
- Displaying a WooCommerce product via PHP
- What exactly does “Posts page” do in WordPress?
- Check if a menu is empty?
- WordPress Template Engine?
- How to have a custom display for both woocommerce archive and product-category pages? [closed]
- wp_remote_get returns an error for valid URL
- On this day PHP code
- Blank on static home page?
- WordPress theme & site not loading after moving files
- Adjust the results quantity for Search Results page pagination
- Exclude pages with certain template from wp_list_pages
- Use Timber/Twig to pull an image by image ID [closed]
- Categories Template Assistance
- Is it possible to use the featured image of a page as a css background without inlining?
- Switching between custom templates in a post type of the admin menu
- Use template for posts with a particular category grandparent
- Placing the_content inside shortcode not working
- Link to file in plugin directory from wordpress template?
- Password protecting content in custom template
- How to override wp-admin styling
- An unwanted inline style is added to my body tag
- Automatically add custom CSS to new posts using a category template
- Render ninja form inside markup
- How can I load a PHP page without using a Template?
- how could I load a different template part by page
- Mass update excerpt
- How can I get a single php file that is the equivalent of an existing WordPress page?
- Get and insert order email address to the PHP template inside HTML text
- Custom search results page not working with empty search
- I have a problem in the order of enqueues while enqueuing stylesheets and scripts for a specific page in my function.php
- code is skipping a div
- Change title only in dynamic page
- Enable custom logo upload if logo is not in header
- How can I edit the content in index.php? [duplicate]
- how to show only specific category for a template
- Show a different code on front page to other pages
- Can’t print Yoast meta description into page template (syntax error, unexpected ‘.’) [closed]
- Using same variable names in files added with get_template_part()
- PHP include is only working in certain places in my custom WP theme
- Use WordPress function in php file
- Adding wrapper elements in the_date() like in the_title()?
- How to get all author posts outside of author templates
- Add filter multiple times using only one master function
- Create a Blog Template Page
- Showing latest post without 301 redirect
- WordPress template page name displayed on screen
- single.php with different look by category
- Function Reference Documenting Template Tags for use in Custom Theme Templates?
- Removing WordPress Footer -without access to PHP code?
- How to set a template with wp_insert_post
- Why is a wp function used in current PHP namespace’s callback not resolved to global scope?
- Adding conditional text to a PHP Shortcode Template
- Create page template via functions.php?
- What’s a good way to allow overwriting files within a child theme if I want the same folder structure?
- how to display this functions?
- is_page_template showing partial results
- Adding regular php file to site
- How to render a block from php template
- Template Loop – add switch case php
- Override Admin menu icon
- Post repeated when opening in overlay, how do I solve this? [closed]
- How can I get “Previous” and “Next” to show in the navigation besides the links?
- Creating custom page template from existing PHP site
- Splitting the_content() by size?
- Gravity Forms merge tags in templates?
- Unable to render custom field after attempt to generate a list of recent post in page template
- php loading different structure than source code
- pass html code to worpdress
- Getting a WordPress tag to print inside of a traditional php echo
- Prevent header and footer from loading on specific pages with template or plugin
- Integrate admin plugin into template. Very interesant (live search + autocomplete with wp rest api, in vanilla js)
- Require()/Include() post template adding extra content
- Display metabox galleries on specific page template in admin editor
- Display WordPress archive template page in 3 columns and not 1 column [closed]
- Run do_shortcode on php template using JS function
- How to hardcode header and footer in WP?
- Change the “Show All” button in a WordPress Portfolio Filter
- Polylang and template files
- How to create dynamic templates?
- If is_page elseif is_page not working like I want it to
- Change WooCommerce template for PDF – access to custom field
- How to display last whole post on the homepage
- missing admin bar and widget in a template
- How to include a function in a template with template tag
- My own theme’s custom widget areas are not working
- How do I modify the Previous and Next Page posts on blog pages to include “previous” and “next” before the links?
- Add point on excerpt post
- WooCommerce – Print Processing orders [closed]
- Loop returns more items than exist?
- How to call a certain object/menubar in a PHP file
- how to register a second page-template
- why is markup routinely placed in functions in wordpress?
- Odd page behaviour after removing sidebar
- If I define a variable in header.php, how do I make it available to templates?
- Loop on a wordpress Page instead of content coming from the WP text editor
- How can one use variables in a template or template part without polluting the global scope?