Does WordPress generate an automatic page for post formats?

Take a look at get_post_format_link() Here’s a little example that uses get_post_format_link() to show a link to the format’s archive page. You can see something similar to this in action on Justin Tadlock’s site. function get_post_format_archive_link() { return sprintf( ‘<a class=”post-format-archive-link %1$s” href=”https://wordpress.stackexchange.com/questions/39925/%2$s”>%1$s</a>’, get_post_format(), get_post_format_link( get_post_format() ) ); } usage: echo get_post_format_archive_link(); The URL Structure … Read more

Passing variables through permalink structure

Solved it! // Register the variables that will be used as parameters on the url function add_my_var($public_query_vars) { $public_query_vars[] = ‘extra_slug’; return $public_query_vars; } add_filter(‘query_vars’, ‘add_my_var’); // Build the rewrite rules, for the extra parameter function do_rewrite() { add_rewrite_rule(‘(accommodation)/[/]?([^/]*)$’, ‘index.php?pagename=accommodation&extra_slug=$matches[2]’,’top’); } add_action(‘init’, ‘do_rewrite’); // The parameter is now accessible get_query_var(‘extra_slug’)

How to embed page content in a blog post

Create a shortcode to embed the content. This will always be synchronized. Sample code from an older project. Just updated. ๐Ÿ™‚ GitHub: https://gist.github.com/3380118 ยท This post in German (auf Deutsch) on my blog. <?php # -*- coding: utf-8 -*- /** * Plugin Name: T5 Embed Post Shortcode * Description: Embed any page, post or custom … Read more

Create WordPress pages with PHP

You can programmatically create posts and pages using wp_insert_post or insert content using WXR files via WordPress’s import feature. To use wp_insert_post see the documentation here: http://codex.wordpress.org/Function_Reference/wp_insert_post A simple example: $my_post = array( ‘post_title’ => ‘hello’, ‘post_content’ => ‘This is my post.’, ‘post_status’ => ‘publish’, ‘post_author’ => 1, ‘post_category’ => array(1), ‘post_type’ => ‘page’ ); … Read more

What is the use of $page_title and how to use it?

Ok my bad found the answer on the codex page but at the very bottom so I’m adding this here as well so if anyone like my didn’t catch it on WordPress’s codex, they can find it here ๐Ÿ™‚ Just use get_admin_page_title(); See the example 1 below: function register_my_custom_submenu_page() { add_submenu_page( ‘tools.php’, ‘My Custom Submenu … Read more

disable password protected page for logged users

Disable the post password protection for (some) users You can try the post_password_required filter (4.7+) to override it for logged in users: add_filter( ‘post_password_required’, function( $returned, $post ) { // Override it for logged in users: if( $returned && is_user_logged_in() ) $returned = false; return $returned; }, 10, 2 ); or disable it for users … Read more

How can I programmatically create “child” pages on theme activation?

As @Soulseekah said, you can do this with post_parent. I didn’t test with the following code, but it should work $pages = array( array( ‘name’ => ‘page1’, ‘title’ => ‘Page 1’, ‘child’ => array( array( ‘name’ => ‘page11’, ‘title’ => ‘Page 1.1’ ), array( ‘name’ => ‘page12’, ‘title’ => ‘Page 1.2’ ) ) ), array( … Read more

Posts in multiple Categories different single.php

Instead of making it category specific you could use post formats and use different content-templates. In single.php you can write <?php get_template_part( ‘content’, get_post_format() ); ?> Then create different post formats add_theme_support( ‘post-formats’, array( ‘withpictures’, ‘withcomments’ ) ); Then create different post templates content-withpictures.php, content-withcomments.php When creating content the chosen post format will determine the … Read more

Get page by template?

The page template’s filename is stored as a post meta with key ‘_wp_page_template’, so basically you can use get_post_meta($post_id, ‘_wp_page_template’, true); to get the template filename for the page with ID $post_id. You can also do the reverse (i.e. getting id from page template filename) using Custom Field Parameters in WP_Query or other wordpress functions. … Read more

Subdomains to pages

It’s better to use WP_Rewrite for that. add_action(‘page_rewrite_rules’,’my_page_rules’); function my_page_rules($rules){ $pageslug = ‘sample-page’; $rules[‘([^/]+)/?$’] = ‘index.php?pagename=”$pageslug”/$matches[1]’; return $rules; } add_filter( ‘page_link’, ‘sub_page_link’); function sub_page_link(){ // preg_replace here } I have found a premium plugin which uses the same mechanism to convert pages into subdomain, it uses rewrite rules and Server WildCard Configured. Hope it is … Read more