Trying to add a page template for my custom post type from a plugin, but it will not display in the template dropdown unless file is in theme

The filter hook you’re using is theme_<post type>_templates, which means that the <post type> part is dynamic and it’s the post type in which you want the custom template be added to the Template dropdown. So since the template is enabled for three post types, you would do so to add the template to the … Read more

How to integrate single and archive templates for custom post type in any WordPress theme

Is there a way to use for example single.php base structure overriding only the inner content? The main content of pages and posts is output using the the_content() function. This can be filtered and changed by plugins using the the_content filter. However this only outputs the content entered into body of the editor. It does … Read more

Create page (not the post type) dynamically

You need to register a ‘rewrite endpoint’ using add_rewrite_endpoint(): <?php add_action( ‘init’, function() { add_rewrite_endpoint( ‘play’, EP_PERMALINK ); } ); Now, after flushing permalinks, in whatever template or code you’re using for your products you can check this to determine whether the /play version of the URL is being accessed: <?php if ( false !== … Read more

Page with posts from category doesn’t work

So, apparently I accidently copied the comment Template Name: Portfolio to my page.php as well, so when I selected the ‘portfolio’ template wordpress just picked page.php out of the two possible templates. May be a warning for other people that have this problem 🙂

How to build a PDF repository in WordPress

Right now, the support for tagging media is pretty disappointing. You can add tags or categories to the attachment post type, but you’ll find the UI is unacceptably bad (it’s a text box where you enter terms separated by commas). There’s a plugin Media Tags that is decent though, so you might look into that. … Read more

changing background color depending on parent page

Using body_class(), by default, WordPress adds classes like parent-pageid-43 to it. This only goes one level deep, though. The code below works for any ancestors of your parent pages, not just children. It relies on the is_page_or_ancestor plugin for that. As kaiser said, body classes are the way to go. You can define the name … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)