Add input field to ‘Pages > Edit Page’ through functions.php

functions.php // Add custom Slider ID field to ‘Edit Page’ add_action( ‘add_meta_boxes’, ‘cd_meta_box_add’ ); function cd_meta_box_add() { add_meta_box( ‘my-meta-box-id’, ‘Slider’, ‘cd_meta_box_cb’, ‘page’, ‘normal’, ‘high’ ); } function cd_meta_box_cb( $post ) { $values = get_post_custom( $post->ID ); $text = isset( $values[‘my_meta_box_text’] ) ? esc_attr( $values[‘my_meta_box_text’][0] ) : ”; wp_nonce_field( ‘my_meta_box_nonce’, ‘meta_box_nonce’ ); ?> <p> <label for=”my_meta_box_text”>Add … Read more

Save page data to an xml file

The save_post hook gets called each time a post is created or updated. Just hook into that. There you can do something like fputcsv(‘/tmp/’ . $post_id, $post) or output to XML/JSON. == EDIT == add_action( ‘save_post’, ‘wp239s5_post_to_xml’, 10, 2 ); function wp239s5_post_to_xml( $post_id, $post ) { if ( defined( ‘DOING_AUTOSAVE’ ) && DOING_AUTOSAVE ) return … Read more

Extra filed under “About the user” user profile

Add following code in theme’s functions.php file. add_action( ‘show_user_profile’, ‘extra_user_profile_fields’ ); add_action( ‘edit_user_profile’, ‘extra_user_profile_fields’ ); function extra_user_profile_fields( $user ) { ?> <table class=”form-table”> <tr> <th><label for=”address”><?php _e(“Designation”); ?></label></th> <td> <input type=”text” name=”designation” id=”designation” value=”<?php echo esc_attr( get_the_author_meta( ‘designation’, $user->ID ) ); ?>” class=”regular-text” /><br /> </td> </tr> <tr> <th><label for=”city”><?php _e(“Linked In”); ?></label></th> <td> <input … Read more

Add an advert every nth Paragraph

The easiest way I can think of is to go through the paragraphs adding the ad text along with your paragraphs: function insert_ad_block( $text ) { if ( is_single() ) : $ads_text=”<div class=”center”>” . get_field(‘blog_post_ad’, ‘option’) . ‘</div>’; $split_by = “\n”; $insert_after = 3; //number of paragraphs // make array of paragraphs $paragraphs = explode( … Read more

Why does this Quick Edit checkbox save the value only when unchecked?

Why the headline_news meta data is deleted on the Edit Post screen, with a fix The qedit_save_post() function stomps on headline_news because $_POST[‘headline_news’] is not set when using the post edit screen. Since the custom fields editor is being used for headline_news and there is no custom meta box involved, we’ll let the built-in custom … Read more

Front-end update_post_meta with ajax

You should check out this document on WordPress.org: http://codex.wordpress.org/AJAX_in_Plugins It gives you everything you need to create front-facing XHR functionality. Make sure to set a nopriv hook for those who aren’t logged in. http://codex.wordpress.org/AJAX_in_Plugins#Ajax_on_the_Viewer-Facing_Side Also the JS variable ajaxurl is only set on the backend. You will need to define that yourself on the front-end. … Read more

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