add_feed and flush_rewrite_rules

You have to check the existing rewrite rules before you run a flush. If your feed name is test, they are stored under the keys ‘feed/(feed|rdf|rss|rss2|atom|test)/?$’ and ‘(feed|rdf|rss|rss2|atom|test)/?$’. So this should do the trick: add_action( ‘init’, function() { $name=”test”; $registered = FALSE; add_feed( $name, ‘test_feed’ ); $rules = get_option( ‘rewrite_rules’ ); $feeds = array_keys( $rules, … Read more

Using get_terms for custom taxonomy in functions.php

You can add the action on the init itself, just increase the priority of the add_action call. The higher the priority the later the function is called. add_action(‘init’, ‘retrieve_my_terms’, 9999); But my suggestion is that you should do these kind of things as late as possible, preferably just before the first time they are used. … Read more

Change page title from plugin

There’s a filter for that: function wpse_alter_title( $title, $id ) { // $id = $post->ID; // alter the title here return $title; } If you want to alter the “Protected” and “Private” titles, then you need other filters: // Preserve the “%s” – else the title will be removed. function wpse_alter_protected_title_format( $title ) { return … Read more

When we register a custom taxonomy or post type, does the WP database modified at all?

When you register post type it is stored in a global var name $wp_post_types and the taxonomies are stored in a global var named $wp_taxonomies Its all in the memory since you need it all and if it was stored in the database you would need to pull it from the database and then it … Read more

when should an action be added to init and when should it be added to wp_head

From Codex Action Reference: init Runs after WordPress has finished loading but before any headers are sent. Useful for intercepting $_GET or $_POST triggers. wp_head Runs when the template calls the wp_head function. This hook is generally placed near the top of a page template between <head> and </head>. This hook does not take any … Read more