Skip to main content

Posts

Showing posts with the label wordpress

Inserting post image programmatically to worpress

We have discussed how posts can be added programmatically before. This comes very much handy when you have to make custom scripts to import content from some cms especially custom ones. But the thing often missed is how to add post image for a particular post programmatically. This is something that is always missed. There very less resources online explaining this. But this is a very straight forward thing and very easy to do. There is this wonderful function that does this beautifully. media_sideload_image($url,$post_id,$description); The first argument is the remote url of the image you want to download. The second argument is the post id of the post to which you want to attach the image. The third argument is optional, but will be a description if included. I'd suggest finding a way to throttle the downloads so that you don't keep timing out, such as limiting the number of images it pulls in per load and setting the importer to refresh itself between dow...

Effective Comment Management in Wordpress

Each people have their on reasons to ask for more control over the comment system, some people want to allow commenting on some posts while some want to close it on some. Some need extra features in comments like subscription or rich text. For some the problem is spam. Here is a random list of plugins that solve these issues. Plugins to combat Fight Spam: Akismet – Anti-spam is a plugin from the creators of WordPress that uses a central database of spam comments to flag spam. Requires a free API key from WordPress.com Spam Karma – Analyzes comments for spam based on a karma system in place. Bad Behavior – Prevents the spambots from even accessing your site by analyzing their HTTP requests. Did You Pass Math? – Asks the commentators a simple math question before their comments are posted. Comment Timeout – Closes comments on all old posts. Encourage Commenting BlogFollow – Shows a snippet of the commenter’s blog at the bottom of the comment. DoFollow – Removes “n...

Highlight your Codes in WordPress Post with Google Syntax Highlighter

One of the problem most of the WordPress newbies face is highlighting their codes in the post. Some even go to the extend of writing their own extension for this purpose. When there are better solutions. Google Syntax Highlighter Plugin is one of the best plugin out there which does this task wonderfully. Its based on this work by Alex Gorbatchev . Here is a screen shot of what it can achieve

Allow contributor to Upload in Wordpress

In WordPress one of the most irritating thing that webmasters with multiple author feel is the lack of permission for the contributor to upload or insert images. When your blog is using post image its really hard as some one with a higher permission has to do the job. But there is a really simple trick to allow this. You just have to add this small piece of code to your functions.php file within your theme. if ( current_user_can('contributor') && !current_user_can('upload_files') ) add_action('admin_init', 'allow_contributor_uploads'); function allow_contributor_uploads() { $contributor = get_role('contributor'); $contributor->add_cap('upload_files'); } Wasn't that easy? For any doubts or suggestion use the comment form.

Customizing the wordpress login page without Plugin

Every one love to see their site totally branded. It does feel good when your users see the WordPress login page when they have to login, may be just to post a comment. Biggest problem come when you are developing for a client. Well though most of them don't know the solution is simple. You don't have to rely on any plugin just to do few modifications on the login page. You just have to add few lines to your functions.php file within your theme folder. "This is the final result, after adding the below code to functions.php" add_action("login_head", "my_login_head"); function my_login_head() { echo "<style>body.login #login h1 a { background: url('".get_bloginfo('template_url')."/styles/logo.gif') no-repeat scroll center top transparent; height: 49px;width: 229px; margin-left:auto;margin-right:auto; } body {background: url('".get_bloginfo('template_url')."/styles/bg.jpg') re...

Adding Custom Post Type in Wordpress

WordPress is no more a blogging platform. People always tried to use it as CMS by applying their own techniques and ways. Wordpress kept on adding new feature in this direction in their releases. One of the most important addition to wordpress in this direction is Custom Post Types. One of the major requirement when using wordpress as a CMS. For example, say you are creating a Travel website listing restaurants & hotels. You would need 2 post types. Restaurant Hotel Ofcourse people used to do this by using categories and all. But that was not a good solution when developing for a client. Now you could add custom post type by adding this small piece of code to your functions.php file within your theme folder: //Add restaurant function post_type_restaurant() { register_post_type( 'restaurant', array( 'label' => __('Restaurant'), 'public' => true, 'show_ui' => true ) ); ...

Using Featured Image in WordPress

Today there are innumerable blogs on any topic you would choose. If you are a blogger your main priority would be to make your blog, stand out! Make it more attractive and tempt people to read what you right. One of the most important technique that major blogs use is setting a featured image for each post. This can be achieved very easily as it 's there in-built in wordpress. But you have to enable it in functions.php file within your theme folder. Here is how you do that: add_theme_support( 'post-thumbnails' ); Paste this within your functions.php file. Additionally you can specify which should have this feature in an array like this: // Add it for posts add_theme_support( 'post-thumbnails', array( 'post' ) ); // Add it for pages add_theme_support( 'post-thumbnails', array( 'page' ) ); You also additional control over this, you explicitly decide the dimension or hard crop the thumbnails etc. The dimension can be set like this: //the scale ...