Monday, October 1, 2012

Change default "Enter title here" text within post title input field

paste the code into your functions.php file.
function title_text_input( $title ){
     return $title = 'Enter new title';
}
add_filter( 'enter_title_here', 'title_text_input' );

Disable theme switching

Paste the following code into functions.php
add_action('admin_init', 'slt_lock_theme');
function slt_lock_theme() {
 global $submenu, $userdata;
 get_currentuserinfo();
 if ($userdata->ID != 1) {
  unset($submenu['themes.php'][5]);
  unset($submenu['themes.php'][15]);
 }
}

Remove menu items from WordPress admin bar

Paste this code into your theme functions.php file to remove menus from the admin bar.
function wps_admin_bar() {
    global $wp_admin_bar;
    $wp_admin_bar->remove_menu('wp-logo');
    $wp_admin_bar->remove_menu('about');
    $wp_admin_bar->remove_menu('wporg');
    $wp_admin_bar->remove_menu('documentation');
    $wp_admin_bar->remove_menu('support-forums');
    $wp_admin_bar->remove_menu('feedback');
    $wp_admin_bar->remove_menu('view-site');
}
add_action( 'wp_before_admin_bar_render', 'wps_admin_bar' );

How to execute shortcodes inside custom fields

By default, WordPress do not allows shortcodes to be executed inside custom fields. If for some reason you need to be able to execute a shortcode inside a specific custom field, here is an easy way to do it.

Just put this code into whatever page you are displaying the results of the shortcode, and change the your_custom_field_here to the name of your custom field.

<?php echo apply_filters('the_content', get_post_meta($post->ID, 'your_custom_field_here', true)); ?>

Monday, September 24, 2012

How to Disable Plugin and Theme Update and Installation on WordPress

Add this constant to your wp-config.php file to disable plugin and theme updates/installation:

define('DISALLOW_FILE_MODS',true);

Monday, September 3, 2012

Get the page ID by the page name

function get_id_by_post_name($post_name)
{
global $wpdb;
$id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name = '".$post_name."' AND post_status='publish'");
return $id;
} 


 

Saturday, September 1, 2012

How To Create A Custom Page Template In WordPress

To create a WordPress Page Template, you’ll need to use your text editor. Go to the directory on your server where you installed WordPress, and then navigate to the directory of your theme. Usually that looks something like this: “/wp-content/themes/default” where “default” is your theme name.

That’s where you will create your custom page template file. Create a file called “cover_page.php” and add the following code to it:
<?php /* Template Name: Cover Page */ ?>
<?php get_header(); ?>
Here's my cover page!
<?php get_footer(); ?>


<?php if (is_page_template('cover_page.php') ) 
{ ?>    <p>Apples</p>    <?php } 
else { ?>    <p>Oranges</p>    <?php } ?>