custom post type archive page has 404 error even though has_archive is true

So it turns out that when the CPT was registered, the following was used in the “rewrite” argument in register_post_type: rewrite => “recipes/%tax_rec_cat%” I don’t know the intention of this, I suppose whoever wrote it thought it was necessary to include both that and the custom_links function I posted in the original question in order … Read more

Is it advisable to use `add_rewrite_rule()` to serve a custom page?

Try instead using the template_redirect hook. Here I have a blogpost on using that approach: http://www.tomjn.com/386/content-without-posts/ I’ve had no issues with the admin toolbar using this method. It includes a helper class: <?php /** * A helper class to implement arbitrary content at arbitrary URLs without a supporting post or page. * Inherit from this … Read more

Permalink for PDF of article

Using add_rewrite_endpoint <?php if ( ! class_exists( ‘PDFRewriteEndpoint’ ) ): class PDFRewriteEndpoint { /** * Add actions and filters in constructor. */ public function __construct() { add_action( ‘parse_request’, array ( $this, ‘sniff_requests’ ), 0 ); add_action( ‘init’, array ( $this, ‘add_endpoint’ ), 0 ); } /** * Add rewrite rules. */ public function add_endpoint() { … Read more

URL Change – Check if Post Exists Before 404

function checkArtist() { $page = get_page_by_path($_SERVER[‘REQUEST_URI’].”https://wordpress.stackexchange.com/”,OBJECT,’artist’); if($page){ header(“HTTP/1.1 301 Moved Permanently”); header(“Location: /artist”.$_SERVER[‘REQUEST_URI’]); } } add_action( ‘wp’, ‘checkArtist’ ); I add a custom hook using wp which as the article says: This hook is one effective place to perform any high-level filtering or validation, following queries, but before WordPress does any routing, processing, or handling. … Read more

Rewrite gets completely ignored

Your rerite rule is incorrect. It should be (assuming download is name or slug of the page): add_rewrite_rule(‘^download/([^/]+)/?$’, ‘index.php?pagename=download&file=$matches[1]’, ‘top’); Also, you need to declare the file query var. A sample and working code: function createRewriteRules() { add_rewrite_tag(‘%file%’, ‘([^&]+)’); add_rewrite_rule(‘^download/([^/]+)/?$’, ‘index.php?pagename=download&file=$matches[1]’, ‘top’); } add_action(‘init’, ‘createRewriteRules’); Note: Don’t forget to flush rewrite rules after adding new … Read more

Mod_rewritte – remove ?m=1 from url

You don’t really need to do anything (unless you have OCD about such things 😉 ) You are not going to redirect to such address and it will die with time, and even if not, the canonical meta in the header will help google to avoid marking it as duplicate content.

WordPress CPT slug and page slug conflicts

As you don’t need the CPT archvie, the easiest way to use example.com/new-site to open a page, and example.com/new-site/post-slug to open single posts of “new-site” post type, is to declare has_archive => false when registering the CPT: add_action( ‘init’, ‘cyb_register_cpt’ ); function cyb_register_cpt() { $args = array( // ….. ‘has_archive’ => false ); register_post_type( ‘new-site’, … Read more

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