Showing posts with label wordpress. Show all posts
Showing posts with label wordpress. Show all posts

Thursday, 15 September 2011

How to get post ancestors of a post?


In wordpress we have an option to assign a post as a child to another post. In order to get the ancestors of a post wordpress have an inbuilt function i.e.  get_post_ancestors( ).

This function will have one argument that can be either post id or post object and it returns the ancestor’s ids as an array. 

$ancestors=get_post_ancestors($post_id);

Tuesday, 13 September 2011

How to Activate or Deactivate wordpress plug-in programmatically?


Recently I had a problem with wordpress plug-in display at the dashboard. I searched on the web but did not find a proper solution. At that time I got a requirement to install one plug-in, I uploaded the plug-in from ftp and the uploaded plug-in is not displayed in the dashboard to activate.

For this I tried the following hook and done the activation of the plug-in.

function activate_plugin() {    
         // Absolute path to your specific plugin
$my_plugin = WP_PLUGIN_DIR.'/wp-email/wp-email.php';
 // Here wp-email is the plug-in which i want to activate. Replace it with the plug-in which you want to activate.
    // Check to see if plugin is already active
    if(is_plugin_active($my_plugin)) {
        // Deactivate plugin
        // Note that deactivate_plugins() will also take an
        // array of plugin paths as a parameter instead of
        // just a single string.
        deactivate_plugins($my_plugin);
    }
    else {
        // Activate plugin
        activate_plugin($my_plugin);
    }
}
toggle_plugin();

Add the above code to the functions.php of your current theme .Once the activation is done comment the code, because we are activating the plug-in if It is in deactivated state and we are deactivating the plug-in if it is active state. So if we did not remove the code the plug-in will be deactivated again.
If you don’t need to deactivation functionality just comment the following line and no need of commenting the whole function
        deactivate_plugins($my_plugin);
This code made my work easy that’s why I am sharing it , so it may be useful for someone.

Thursday, 21 July 2011

How to avoid the image alignment problem in Wordpress?


Wordpress has an excellent feature of adding images into a post while at the time of adding a new post or at the time of editing post. After adding images into post we can align those to different positions like left, right, center and none along with the text.


Some times we will get a problem like the image is not aligned properly as per the selection. To avoid this problem add the following lines of code into your selected theme stylesheet.

/* =WordPress Core
-------------------------------------------------------------- */
.alignnone {
    margin: 5px 20px 20px 0;
}

.aligncenter, div.aligncenter {
    display:block;
    margin: 5px auto 5px auto;
}

.alignright {
    float:right;
    margin: 5px 0 20px 20px;
}

.alignleft {
    float:left;
    margin: 5px 20px 20px 0;
}

.aligncenter {
    display: block;
    margin: 5px auto 5px auto;
}

a img.alignright {
    float:right;
    margin: 5px 0 20px 20px;
}

a img.alignnone {
    margin: 5px 20px 20px 0;
}

a img.alignleft {
    float:left;
    margin: 5px 20px 20px 0;
}

a img.aligncenter {
    display: block;
    margin-left: auto;
    margin-right: auto
}

.wp-caption {
    background: #fff;
    border: 1px solid #f0f0f0;
    max-width: 96%; /* Image does not overflow the content area */
    padding: 5px 3px 10px;
    text-align: center;
}

.wp-caption.alignnone {
    margin: 5px 20px 20px 0;
}

.wp-caption.alignleft {
    margin: 5px 20px 20px 0;
}

.wp-caption.alignright {
    margin: 5px 0 20px 20px;
}

.wp-caption img {
    border: 0 none;
    height: auto;
    margin:0;
    max-width: 98.5%;
    padding:0;
    width: auto;
}

.wp-caption p.wp-caption-text {
    font-size:11px;
    line-height:17px;
    margin:0;
    padding:0 4px 5px;
}

If you need more information about this issue just refer the following link
http://codex.wordpress.org/CSS

Wednesday, 13 July 2011

Wordpress login url change with .htaccess

Thought to change Wordpress default login url "http://www.website.com/wp-login.php" to something like "http://www.website.com/wlogin" , tried this code and it works fine for me and i am sharing this to all who want to change like me.
 To do this you have to add the following code to your .htaccess file which is located at your root directory of your wordpress install.

RewriteRule  ^wlognin$  http://website.com/wp-login.php [NC,L]