How To Set Simple Embedding PDF Shortcode In WordPress
The following snippet will let you set simple embedding PDF shortcode in WordPress.
1 2 3 4 |
function viewpdf($attr, $url) { return '<iframe src="http://docs.google.com/viewer?url=' . $url . '&embedded=true" style="width:' .$attr['width']. '; height:' .$attr['height']. ';" frameborder="0">Your browser should support iFrame to view this PDF document</iframe>'; } add_shortcode('embedpdf', 'viewpdf'); |
Snippet Source/Credit: WPRecipes.com
How To Set Slug As String In WordPress
The following snippet will let you set slug as string in WordPress.
1 2 3 4 5 |
<?php $post_data = get_post($post->ID, ARRAY_A); $slug = $post_data['post_name']; echo $slug; ?> |
Snippet Source/Credit: insitewebsitedesign.com
How To Set WordPress Options As Value
The following snippet will let you set WordPress options as value.
1 2 3 4 5 6 |
<?php global $options; foreach ($options as $value) { if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); } } ?> |
How To Set WordPress Post Expiration Code
The following snippet will let you set WordPress post expiration code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<?php //to check against expiration date; $timestamp = strtotime("now + 8 hours"); $currentdate = date('YmdHis', $timestamp); $expirationdate = get_post_custom_values('expiration'); if (is_null($expirationdate)) { $expirestring = '30005050235959'; //MAKE UN-EXPIRING POSTS ALWAYS SHOW UP; } else { if (is_array($expirationdate)) { $expirestringarray = implode($expirationdate); } $markup = array("/",":"," "); $expirestring = str_replace($markup,"",$expirestringarray); } //else if (( $expirestring > $currentdate ) || (is_archive())) { ?> <?php } //end if for expiration; ?> |
Snippet Source/Credit: nrbet.com
How To Share Databases Between Two Domains In WordPress
The following snippet will let you share databases between two domains in WordPress.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
Install the second WP as normal into the same database as the original with a DIFFERENT table prefix. Activate the theme you want to use. Now edit these files... In wp-config: define('CUSTOM_CAPABILITIES_PREFIX', 'wp_'); define('CUSTOM_USER_TABLE', 'wp_users'); define('CUSTOM_USER_META_TABLE', 'wp_usermeta'); In wp-includes/capabilities.php: /** * Set up capability object properties. * * Will set the value for the 'cap_key' property to current database table * prefix, followed by 'capabilities'. Will then check to see if the * property matching the 'cap_key' exists and is an array. If so, it will be * used. * * @since 2.1.0 * * @param string $cap_key Optional capability key * @access protected */ function _init_caps( $cap_key = '' ) { global $wpdb; if ( empty($cap_key) ) if (defined ('CUSTOM_CAPABILITIES_PREFIX')) { $this->cap_key = CUSTOM_CAPABILITIES_PREFIX . 'capabilities'; } else { $this->cap_key = $wpdb->prefix . 'capabilities'; } else $this->cap_key = $cap_key; $this->caps = &$this->{$this->cap_key}; if ( ! is_array( $this->caps ) ) $this->caps = array(); $this->get_role_caps(); } In the active theme's functions.php: function table_prefix_switch() { global $wpdb; $options = $wpdb->options; //Save the site 2 options table $wpdb->set_prefix('wp_'); //The prefix to site 1 $wpdb->options = $options; //Put the options table back } add_action('init', 'table_prefix_switch'); Install the second WP as normal into the same database as the original with a DIFFERENT table prefix. Activate the theme you want to use. Now edit these files... In wp-config: define('CUSTOM_CAPABILITIES_PREFIX', 'wp_'); define('CUSTOM_USER_TABLE', 'wp_users'); define('CUSTOM_USER_META_TABLE', 'wp_usermeta'); In wp-includes/capabilities.php: /** * Set up capability object properties. * * Will set the value for the 'cap_key' property to current database table * prefix, followed by 'capabilities'. Will then check to see if the * property matching the 'cap_key' exists and is an array. If so, it will be * used. * * @since 2.1.0 * * @param string $cap_key Optional capability key * @access protected */ function _init_caps( $cap_key = '' ) { global $wpdb; if ( empty($cap_key) ) if (defined ('CUSTOM_CAPABILITIES_PREFIX')) { $this->cap_key = CUSTOM_CAPABILITIES_PREFIX . 'capabilities'; } else { $this->cap_key = $wpdb->prefix . 'capabilities'; } else $this->cap_key = $cap_key; $this->caps = &$this->{$this->cap_key}; if ( ! is_array( $this->caps ) ) $this->caps = array(); $this->get_role_caps(); } In the active theme's functions.php: function table_prefix_switch() { global $wpdb; $options = $wpdb->options; //Save the site 2 options table $wpdb->set_prefix('wp_'); //The prefix to site 1 $wpdb->options = $options; //Put the options table back } add_action('init', 'table_prefix_switch'); |
Snippet Source/Credit: WordPress.org