Adding a link in edit.php
-
In the title column under the title of each post there are by default 4 links. How can I add a link there? This would be the first step for the price managing of each apartment (post)
The page I need help with: [log in to see the link]
-
You can add this to your functions.php file or you can make it into a plugin:
// Register the custom link function custom_post_row_actions($actions, $post) { // Change 'New Link' to the label you want to display for your link $actions['new_link'] = '<a href="' . esc_url(admin_url('admin.php?page=your_custom_page&post=' . $post->ID)) . '">New Link</a>'; return $actions; } add_filter('post_row_actions', 'custom_post_row_actions', 10, 2);
If I put it, it brakes the site. Maybe you can point the example to a real page? i.e: https://test.sacconicase.com/case-vacanza/italia/toscana/marina-di-massa-appartamenti-vacanze/
The href URL should be the one necessary for whatever it is you want to do when the link is followed. Perhaps to a form similar to Quick Edit where one can manage prices? Or perhaps price data could be added to the default Quick Edit form?
I’m unsure right now how to customize Quick Edit, but I’m pretty confident there’s a way. I’m afraid it might be rather complex for a sorcerer’s apprentice though. I suspect it’d be quite a learning experience ??
At the moment I’d like just to see a link appear in the links area. This link should lead to a page to manage prices (specific for each apartment/post), I let you see how it works my current website sacconicase.it: https://ibb.co/SdYNHBq and https://ibb.co/xqRtSt6
there is a general apartments table with some filters, rightside you see some links i.e. the link “prezzi” (prices), you click the link and get the prices manager area
Why wouldn’t you just use the existing “Edit” link and alter the price on the apartment/post’s normal edit screen?
Anyway, you can add a link like abretado1985 suggested, but have the link lead to a custom admin page which contains anything you like. The easiest way to add custom admin pages is with
add_menu_page()
andadd_submenu_poage()
, but the sort of price edit page you envision would need to be passed information on what post to set prices for. You don’t get that from a generic admin menu item. I suppose you can add a menu page to establish the URL, then hide the item in the admin menu.Another way to add admin pages which doesn’t add menu items is to use the /wp-admin/admin-post.php path. The path will need an “action” query var appended which defines a callback to use which does the actual output of page content. Also append the post ID as a query string so the page knows which post to set prices for. For example:
/wp-admin/admin-post.php?action=set_apt_price&aptID=1234
ok,maybe the simplest solution is using the existing “edit” link, but since my post edit page is already full of taxonomies and custom fields I would order the content with tabs, like this: https://ibb.co/M2Pv15T , what I should do to develop this solution?
Did you know that if you use the classic editor plugin the various meta boxes can be moved about? You could move the meta box with prices to a more prominent position. There’s a setting in the plugin that allows users to freely switch between classic and Gutenberg. The meta box arrangement is unique per user.
Making tabbed pages out of an editor screen would involve adding CSS to initially hide most of the content. Then you’d use JavaScript to switch what’s visible or not based on click events on the tab links across the top of the page. There’s likely an action hook you could use to output the tab links. I’m not sure how feasible this is for an editor screen, but that’s the general approach. It’s no different than any other tabbed page.
You might instead look into adding the price field to the quick edit box. It looks like you would add a custom column to the post list table. Then use the ‘quick_edit_custom_box’ action to output the field.
Yes I know. Finally I’ll use the usual post editor. Maybe I can set an anchor from a new link in administration posts table and the price manager area in my edit single post page. To begin with, where I have to write the link destination in the above code? where in this sequence:
'<a href="'
this way?
'<a
Which “above code”? The code suggested by abretado1985?
You would assign the complete link HTML:
$actions['new_link'] = '<a href="your-price-manager-link-here">Set Price</a>';
You cannot hardcode the entire URL though. You need to at least dynamically set the target slug from the passed $post. You should actually dynamically set the entire URL, otherwise you’d need to edit code in order to move to a different domain or subdomain. Something more like:
$actions['new_link'] = '<a href="'. site_url("/{$post->post_name}/") .'">Set Price</a>';
But that URL will be the same as the “View” action item URL. What would be the correct URL to use here? It should pass data on the current $post object, such as
$post->ID
. abretado1985’s suggested URL is probably closer to what you should do, but you need to use the correct slug in place of “your-custom-page”
- The topic ‘Adding a link in edit.php’ is closed to new replies.