{"id":1439,"date":"2017-04-21T21:46:56","date_gmt":"2017-04-21T12:46:56","guid":{"rendered":"https:\/\/n8finch2024.local\/?p=1439"},"modified":"2017-05-03T21:47:50","modified_gmt":"2017-05-03T12:47:50","slug":"use-filter-tinymce-add-buttons","status":"publish","type":"post","link":"https:\/\/n8finch2024.local\/use-filter-tinymce-add-buttons\/","title":{"rendered":"How to Use a Filter on TinyMCE to Add Buttons"},"content":{"rendered":"

Recently, I was asked to add a button\u00a0to the visual editor for posts and pages on a WordPress install that would insert the <!--nextpage--><\/code>\u00a0code for article pagination . I had done this before, but wanted to write about it here, since I’d totally forgotten how to do it, and wanted to make sure I had\u00a0a snippet or two for reference.<\/p>\n

<\/p>\n

TinyMCE<\/strong><\/a> is described on their site as:<\/p>\n

The most advanced WYSIWYG HTML editor.<\/p><\/blockquote>\n

Whether it is or not, I don’t know, I haven’t tested them all. Suffice to say this is what is in WP Core, so this is what I’m using!<\/p>\n

There’s some helpful documentation and code snippets on the TinyMCE\u00a0WordPress Codex<\/strong><\/a> page as well. After reviewing everything, it looks like all I need to do is:<\/p>\n

    \n
  1. determine which filter to hook into<\/li>\n
  2. find out if the button I need already exists but isn’t being used<\/li>\n
  3. make a custom button if one is not already provided in Core.<\/li>\n<\/ol>\n

    Thankfully, I found what I needed in Core, but if I had to make a custom button, I’d start my research here, and also find a plugin that adds a custom button to the TinyMCE WYSIWYG editor.<\/p>\n

    After grepping<\/code> for the “Read more…” tag, I\u00a0found some other available button objects in the following file:<\/p>\n

    \n

    wp-includes\/js\/tinymce\/plugins\/wordpress\/plugin.js<\/span><\/p>\n<\/blockquote>\n

    These included the “Read more” button and the “Page break” button, which is what I needed.<\/p>\n

    The simple filter to add the code back in is below.<\/p>\n

    \r\n\r\n\/**\r\n* Add Next Page Break into TinyMCE in the second row\r\n*\/\r\nfunction n8f_add_page_break( $buttons ) {\r\n\/**\r\n* Add in a core button that's disabled by default\r\n*\/\r\n$buttons[] = 'wp_page';\r\n\r\nreturn $buttons;\r\n}\r\nadd_filter( 'mce_buttons_2', 'n8f_add_page_break' );\r\n\r\n<\/pre>\n

    It could not have been easier… Ok, maybe a little easier, but this is the simple way I went about\u00a0how\u00a0to use a filter on TinyMCE to add buttons.<\/p>\n","protected":false},"excerpt":{"rendered":"

    Recently, I was asked to add a button\u00a0to the visual editor for posts and pages on a WordPress install that would insert the <!–nextpage–>\u00a0code for article pagination . I had done this before, but wanted to write about it here, since I’d totally forgotten how to do it, and wanted to make sure I had\u00a0a […]<\/p>\n","protected":false},"author":1,"featured_media":1476,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_eb_attr":"","footnotes":""},"categories":[1,37,8,26],"tags":[],"yoast_head":"\nHow to Use a Filter on TinyMCE to Add Buttons | Nate Finch<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/n8finch-site.site.strattic.io\/use-filter-tinymce-add-buttons\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Use a Filter on TinyMCE to Add Buttons | Nate Finch\" \/>\n<meta property=\"og:description\" content=\"Recently, I was asked to add a button\u00a0to the visual editor for posts and pages on a WordPress install that would insert the <!--nextpage-->\u00a0code for article pagination . I had done this before, but wanted to write about it here, since I’d totally forgotten how to do it, and wanted to make sure I had\u00a0a […]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/n8finch-site.site.strattic.io\/use-filter-tinymce-add-buttons\/\" \/>\n<meta property=\"og:site_name\" content=\"Nate Finch\" \/>\n<meta property=\"article:published_time\" content=\"2017-04-21T12:46:56+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-05-03T12:47:50+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/n8finch-site.site.strattic.io\/wp-content\/uploads\/2020\/11\/plugin_js_____Desktop_rimonthly_wp-includes_js_tinymce_plugins_wordpress_t7fyfc.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1862\" \/>\n\t<meta property=\"og:image:height\" content=\"878\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Nate\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@n8finch\" \/>\n<meta name=\"twitter:site\" content=\"@n8finch\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nate\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/n8finch-site.site.strattic.io\/use-filter-tinymce-add-buttons\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/n8finch-site.site.strattic.io\/use-filter-tinymce-add-buttons\/\"},\"author\":{\"name\":\"Nate\",\"@id\":\"https:\/\/n8finch.local\/#\/schema\/person\/619068414583ca3c43bb135af49a47ce\"},\"headline\":\"How to Use a Filter on TinyMCE to Add Buttons\",\"datePublished\":\"2017-04-21T12:46:56+00:00\",\"dateModified\":\"2017-05-03T12:47:50+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/n8finch-site.site.strattic.io\/use-filter-tinymce-add-buttons\/\"},\"wordCount\":339,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/n8finch.local\/#\/schema\/person\/619068414583ca3c43bb135af49a47ce\"},\"articleSection\":[\"Blog\",\"Snippets\",\"Web Development\",\"What I Learned\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/n8finch-site.site.strattic.io\/use-filter-tinymce-add-buttons\/\",\"url\":\"https:\/\/n8finch-site.site.strattic.io\/use-filter-tinymce-add-buttons\/\",\"name\":\"How to Use a Filter on TinyMCE to Add Buttons | Nate Finch\",\"isPartOf\":{\"@id\":\"https:\/\/n8finch.local\/#website\"},\"datePublished\":\"2017-04-21T12:46:56+00:00\",\"dateModified\":\"2017-05-03T12:47:50+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/n8finch-site.site.strattic.io\/use-filter-tinymce-add-buttons\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/n8finch-site.site.strattic.io\/use-filter-tinymce-add-buttons\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/n8finch-site.site.strattic.io\/use-filter-tinymce-add-buttons\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/n8finch.local\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Use a Filter on TinyMCE to Add Buttons\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/n8finch.local\/#website\",\"url\":\"https:\/\/n8finch.local\/\",\"name\":\"Nate Finch\",\"description\":\"All the things, keeping it clever...🤓\",\"publisher\":{\"@id\":\"https:\/\/n8finch.local\/#\/schema\/person\/619068414583ca3c43bb135af49a47ce\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/n8finch.local\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/n8finch.local\/#\/schema\/person\/619068414583ca3c43bb135af49a47ce\",\"name\":\"Nate\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/n8finch.local\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/n8finch2024.local\/wp-content\/uploads\/2020\/11\/nate-pic_ykd6mq.jpg\",\"contentUrl\":\"https:\/\/n8finch2024.local\/wp-content\/uploads\/2020\/11\/nate-pic_ykd6mq.jpg\",\"width\":796,\"height\":792,\"caption\":\"Nate\"},\"logo\":{\"@id\":\"https:\/\/n8finch.local\/#\/schema\/person\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Use a Filter on TinyMCE to Add Buttons | Nate Finch","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/n8finch-site.site.strattic.io\/use-filter-tinymce-add-buttons\/","og_locale":"en_US","og_type":"article","og_title":"How to Use a Filter on TinyMCE to Add Buttons | Nate Finch","og_description":"Recently, I was asked to add a button\u00a0to the visual editor for posts and pages on a WordPress install that would insert the <!--nextpage-->\u00a0code for article pagination . I had done this before, but wanted to write about it here, since I’d totally forgotten how to do it, and wanted to make sure I had\u00a0a […]","og_url":"https:\/\/n8finch-site.site.strattic.io\/use-filter-tinymce-add-buttons\/","og_site_name":"Nate Finch","article_published_time":"2017-04-21T12:46:56+00:00","article_modified_time":"2017-05-03T12:47:50+00:00","og_image":[{"width":1862,"height":878,"url":"https:\/\/n8finch-site.site.strattic.io\/wp-content\/uploads\/2020\/11\/plugin_js_____Desktop_rimonthly_wp-includes_js_tinymce_plugins_wordpress_t7fyfc.png","type":"image\/png"}],"author":"Nate","twitter_card":"summary_large_image","twitter_creator":"@n8finch","twitter_site":"@n8finch","twitter_misc":{"Written by":"Nate","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/n8finch-site.site.strattic.io\/use-filter-tinymce-add-buttons\/#article","isPartOf":{"@id":"https:\/\/n8finch-site.site.strattic.io\/use-filter-tinymce-add-buttons\/"},"author":{"name":"Nate","@id":"https:\/\/n8finch.local\/#\/schema\/person\/619068414583ca3c43bb135af49a47ce"},"headline":"How to Use a Filter on TinyMCE to Add Buttons","datePublished":"2017-04-21T12:46:56+00:00","dateModified":"2017-05-03T12:47:50+00:00","mainEntityOfPage":{"@id":"https:\/\/n8finch-site.site.strattic.io\/use-filter-tinymce-add-buttons\/"},"wordCount":339,"commentCount":0,"publisher":{"@id":"https:\/\/n8finch.local\/#\/schema\/person\/619068414583ca3c43bb135af49a47ce"},"articleSection":["Blog","Snippets","Web Development","What I Learned"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/n8finch-site.site.strattic.io\/use-filter-tinymce-add-buttons\/","url":"https:\/\/n8finch-site.site.strattic.io\/use-filter-tinymce-add-buttons\/","name":"How to Use a Filter on TinyMCE to Add Buttons | Nate Finch","isPartOf":{"@id":"https:\/\/n8finch.local\/#website"},"datePublished":"2017-04-21T12:46:56+00:00","dateModified":"2017-05-03T12:47:50+00:00","breadcrumb":{"@id":"https:\/\/n8finch-site.site.strattic.io\/use-filter-tinymce-add-buttons\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/n8finch-site.site.strattic.io\/use-filter-tinymce-add-buttons\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/n8finch-site.site.strattic.io\/use-filter-tinymce-add-buttons\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/n8finch.local\/"},{"@type":"ListItem","position":2,"name":"How to Use a Filter on TinyMCE to Add Buttons"}]},{"@type":"WebSite","@id":"https:\/\/n8finch.local\/#website","url":"https:\/\/n8finch.local\/","name":"Nate Finch","description":"All the things, keeping it clever...🤓","publisher":{"@id":"https:\/\/n8finch.local\/#\/schema\/person\/619068414583ca3c43bb135af49a47ce"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/n8finch.local\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/n8finch.local\/#\/schema\/person\/619068414583ca3c43bb135af49a47ce","name":"Nate","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/n8finch.local\/#\/schema\/person\/image\/","url":"https:\/\/n8finch2024.local\/wp-content\/uploads\/2020\/11\/nate-pic_ykd6mq.jpg","contentUrl":"https:\/\/n8finch2024.local\/wp-content\/uploads\/2020\/11\/nate-pic_ykd6mq.jpg","width":796,"height":792,"caption":"Nate"},"logo":{"@id":"https:\/\/n8finch.local\/#\/schema\/person\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/n8finch2024.local\/wp-json\/wp\/v2\/posts\/1439"}],"collection":[{"href":"https:\/\/n8finch2024.local\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/n8finch2024.local\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/n8finch2024.local\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/n8finch2024.local\/wp-json\/wp\/v2\/comments?post=1439"}],"version-history":[{"count":3,"href":"https:\/\/n8finch2024.local\/wp-json\/wp\/v2\/posts\/1439\/revisions"}],"predecessor-version":[{"id":1475,"href":"https:\/\/n8finch2024.local\/wp-json\/wp\/v2\/posts\/1439\/revisions\/1475"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/n8finch2024.local\/wp-json\/wp\/v2\/media\/1476"}],"wp:attachment":[{"href":"https:\/\/n8finch2024.local\/wp-json\/wp\/v2\/media?parent=1439"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/n8finch2024.local\/wp-json\/wp\/v2\/categories?post=1439"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/n8finch2024.local\/wp-json\/wp\/v2\/tags?post=1439"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}