Ways to handle SVG rendering in wordpress?

Take a look at wp_prepare_attachment_for_js(), which is what gathers attachment metadata for use on the Media pages. The eponymous filter lets us add or alter metadata. The following example can be dropped into functions.php. Note: this requires SimpleXML support in PHP. function common_svg_media_thumbnails($response, $attachment, $meta){ if($response[‘type’] === ‘image’ && $response[‘subtype’] === ‘svg+xml’ && class_exists(‘SimpleXMLElement’)) { … Read more

Do something after sending email

Using the PHPMailer class with an action callback: I did some digging into the PHPMailer class and found that it supports a custom action. Here’s how the callback is activated with the doCallback() method in the class. There’s also a PHPMailer test on GitHub using this feature via the callbackAction() callback. We can set it … Read more

How to Add a Third Level Sub Menu to the WordPress Admin Menu

No, it is not possible to create third level menu in admin panel. If you look at the definition of add_submenu_page, you need to mention the parent slug name. For eg: add_menu_page ( ‘Test Menu’, ‘Test Menu’, ‘read’, ‘testmainmenu’, ”, ” ); add_submenu_page ( ‘testmainmenu’, ‘Test Menu’, ‘Child1’, ‘read’, ‘child1’, ”); The first parameter of … Read more

Add self-closing shortcode button to TinyMCE in WP 4.6

We start by adding the custom TinyMCE Button: function add_mce_button_custom_em() { // check user permissions if ( !current_user_can( ‘edit_posts’ ) && !current_user_can( ‘edit_pages’ ) ) { return; } // check if WYSIWYG is enabled if ( ‘true’ == get_user_option( ‘rich_editing’ ) ) { add_filter( ‘mce_external_plugins’, ‘add_tinymce_plugin_custom_em’ ); add_filter( ‘mce_buttons’, ‘register_mce_button_custom_em’ ); } } add_action(‘admin_head’, ‘add_mce_button_custom_em’); … Read more

What is the “Advanced” $context in add_meta_box?

The difference between normal and advanced is that normal will be placed on the page before advanced. For example the following will display “One” before “Two” function admin_init_test() { add_meta_box(‘one’, __(‘One’), ‘test_one’, ‘post’, ‘advanced’); add_meta_box(‘two’, __(‘Two’), ‘test_two’, ‘post’, ‘normal’); } add_action(‘admin_init’, ‘admin_init_test’); function test_two() { echo “<p>test_two</p>”; } function test_one() { echo “<p>test_one</p>”; } If … Read more

Enable page templates. How?

Chances are that the theme you’ve switched to has no page templates defined – they exist on a per theme basis. Here’s the Codex reference: https://wordpress.org/support/article/pages/

How to show all posts of the category in wordpress?

<?php $args = array( ‘category’ => 7, ‘post_type’ => ‘post’ ); $postslist = get_posts( $args ); foreach ($postslist as $post) : setup_postdata($post); ?> <h2><a href=”https://wordpress.stackexchange.com/questions/17496/<?php the_permalink(); ?>”><?php the_title(); ?></a></h2> <?php the_excerpt(); ?> <?php endforeach; ?> just change the category id (number 7) and change the post_type that was in the plugin to learn more about … Read more

Redirect Main Site to Subsite in Multisite WordPress

You can use the parse_request action to accomplish this. Simply enable this plugin on your primary blog. Place the following code in a .php file and upload it to your plugins directory. /* Plugin Name: Redirect Main Site To Sub-Site Description: Redirect ‘main-site’ to ‘main-site/sub-site/’ Version: 0.1 Author: WPSE Author URI: http://wordpress.stackexchange.com License: GPL2 */ … Read more