Organizing the Navigation Menu

Check nav menu target URL for ‘/pressroom/’, then check if it’s a post. If it fits, add custom class to that menu item. <?php function my_add_posts_page_ancestor_class( $classes, $item ) { if( false !== strpos($item->url, ‘/pressroom/’) && is_single($item->ID) && !is_page($item->ID) ) { $classes[] = ‘my-ancestor-class’; } return $classes; } add_filter(‘nav_menu_css_class’, ‘my_add_posts_page_ancestor_class’, 10, 2); The code is … Read more

wordpress url correction

Copy the index.php and .htaccess file(Just copy it , do not move it ) from myblog directory to root directory. Open index.php file in any text editor and find the following code in the file. /** Loads the WordPress Environment and Template */ require(‘./wp-blog-header.php’); Replace it with the following code and save the file. /** … Read more

Post’s ID pattern?

Each auto-draft gets its own ID, each revision, each nav item, page, custom post type … The actual ID of a post should be irrelevant, this is really just needed for the database and ugly permalinks. You cannot get the last 30 items by inspecting the post ID only. Install a REST API on the … Read more

How to remove the number of a comment in the url slug?

The asker solved the issue with $_SERVER[“HTTP_REFERER”] but refused to post that as a real solution. Let me suggest something better, because the referer might be empty or full of malicious code. Never use that. First, we make sure, we get both arguments for that hook: add_filter( ‘comment_post_redirect’, ‘wpse_97580_comment_redirect’, 10, 2 ); Then we use … Read more

How to parse a custom url (within WP site) and obtain params passed to that URL

First, you register your query vars param1 and param2: function wpse_101951_query_vars( $qv ) { $qv[] = ‘param1’; $qv[] = ‘param2’; return $qv; } add_filter( ‘query_vars’, ‘wpse_101951_query_vars’ ); To use this information, you can pretty much hook into any action or filter after parse_query. That’s the first action available after the query vars are set, so … Read more

Suddenly new posts have the default permalink instead of the post name

Nothing just happens for “no apparent reason”. Some new condition has caused this. Most likely a new plugin or update of an existing plugin. It is possible for a plugin or theme doing something crazy like flushing rewrite rules on every load could wipeout the existing rules. See this ticket for more info: http://core.trac.wordpress.org/ticket/18450#comment:34 if … Read more

How can I make my blog urls have words of the title in them?

From the WordPress Codex, this is how to enable permalinks in your blog. From your admin dashboard on the left side go to Settings -> Permalinks In the Settings → Permalinks panel (Options → Permalinks before WordPress 2.5), you can choose one of the “common” structures or enter your own in the “Custom structure” field … Read more