Post/Page Preview Template

You could use the conditional is_preview() to add a bit of extra content. For instance, you could put this at the very top of your single.php right after the header is called – or you could put it in your header.php file if you want it shown at the very top of the page: <?php … Read more

Dynamically add id to heading tags

I had this very same dilemma, and I found this plugin: Add IDs to Header Tags, and it works fine for posts. (I’m not affiliated to the plugin in any way). To make it work for pages too, I had to make a change in the code, which is explained on this support page: Not … Read more

WordPress removing tags?

This is pretty much what Foxsk8 mentioned in a comment, so credit should go to him, but these additional instructions will be useful. The WordPress plugin called TinyMCE Advanced will solve your problem. This plugin comes with an option inside Settings > TinyMCE Advanced that will fix your disappearing <p> tags. Mark the checkbox labeled … Read more

Find out who deleted a page or post?

By default, no, WordPress doesn’t keep track of who changes post statuses (at least that I can see). you can hook into transition_post_status and log the user id. add_action( ‘transition_post_status’, ‘wwm_transition_post_status’, 10, 3 ); function wwm_transition_post_status( $new_status, $old_status, $post ) { if ( ‘trash’ == $new_status ) { $uid = get_current_user_id(); //somehow or another log … Read more

How to validate XML-RPC post creation and cancel when needed?

It looks like the xmlrpc_prepare_post filter is only applied to the output of the wp_getPost and wp_getRevision methods of the wp_xmlrpc_server class. It would be great if this code line: do_action( ‘xmlrpc_call’, ‘wp.newPost’ ); would be replaced with extra input arguments, for example: do_action( ‘xmlrpc_call’, ‘wp.newPost’, …, $content_struct ); but that’s not going to happen … Read more

Hook that get’s triggered when the author of a post is changed

There is no special hook to author change. But you can achieve it by using post_updated hook. Example: add_action(‘post_updated’, ‘prefix_on_update_author’, 10, 3); function prefix_on_update_author($post_ID, $post_after, $post_before) { if ($post_after->post_author != $post_before->post_author) { // author has been changed // you can add your own hook here or write your code } } Here is the codex … Read more

How set featured posts using checkbox in post edit screen?

You can do this by following these steps: Add a custom meta box to your posts Create a function to save the meta data using the save_post action Add the ‘meta_key’ query argument to whatever query you are using. Place this in your themes functions.php file: function register_post_assets(){ add_meta_box(‘featured-post’, __(‘Featured Post’), ‘add_featured_meta_box’, ‘post’, ‘advanced’, ‘high’); … Read more

Get current post id in functions.php

If you hook your localize script function to wp_enqueue_scripts, then you will have access to the global $post variable. As long as you pick a hook at or after ‘wp’ you should have access to the global $post. <?php add_action(‘wp_enqueue_scripts’, ‘YOUR_NAME_scripts’); function YOUR_NAME_scripts() { wp_enqueue_script(‘YOUR_NAME-js’); global $post; $params = array( ‘site_url’ => site_url(), ‘admin_ajax_url’ => … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)