Skip Navigation

[Resolved] Edit posttype form with wysiwyg field. Disable linksettingsbutton

This thread is resolved. Here is a description of the problem and solution.

Problem: I have a WYSIWYG field that includes a link button. I would like to restrict existing content links by post type.

Solution: The following code sample shows how to restrict entire post types from the existing content link menu:

// filter custom post types out of existing content link options in tinyMCE 
function custom_wp_link_query_args($query)
{
  $pt_new = array();
  $exclude_types = array( 'book', 'chapter' );
  foreach ($query['post_type'] as $pt)
  {
    if (in_array($pt, $exclude_types)) continue;
    $pt_new[] = $pt;
  }
  $query['post_type'] = $pt_new;
  return $query;
}
add_filter('wp_link_query_args', 'custom_wp_link_query_args');

Relevant Documentation:
https://codex.wordpress.org/Plugin_API/Filter_Reference/wp_link_query_args

This support ticket is created 5 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 2 replies, has 2 voices.

Last updated by sandraB-2 5 years, 11 months ago.

Assisted by: Christian Cox.

Author
Posts
#1207771
3.gif
2.gif
1.gif

Hi,

I am building a cred form so that a profile owner can edit his or her article. In a WYSIWYG-field people are able to insert a link with the tinyMCE button 'insert link'. In the field that opens on the right side there is a buttin 'Link settings'. If you open that you can select Exsisting content in a list. In that list there are also posts from custom post types that should not be selected. Can I or remove those entries from that list, or remove the list of remove the button. So that the users can not select the wrong links.

My site is under construction. There is a online version but not publicly open. I can provide inlogs for you if you need them.

Kind Regards,
Sandra Berends

#1207982

Hi you can filter out entire post types like this:

// filter custom post types out of existing content link options in tinyMCE 
function custom_wp_link_query_args($query)
{
  $pt_new = array();
  $exclude_types = array( 'book', 'chapter' );
  foreach ($query['post_type'] as $pt)
  {
    if (in_array($pt, $exclude_types)) continue;
    $pt_new[] = $pt;
  }
  $query['post_type'] = $pt_new;
  return $query;
}
add_filter('wp_link_query_args', 'custom_wp_link_query_args');

Replace book and chapter with a comma-separated list of the slugs of post types you want to exclude. Wrap each slug in quotes.

More information about the wp_link_query_args hook is available here: https://codex.wordpress.org/Plugin_API/Filter_Reference/wp_link_query_args

#1208146

Thank you very much, Christian. Ik works! You made my day!!
Regards,
Sandra