Showing posts with label Wordpress. Show all posts
Showing posts with label Wordpress. Show all posts

Wednesday, 2 March 2016

How to get page ID from Page Title Wordpress


How to get page ID from Page Title Wordpress

global $wpdb;

$page_name = "Your page title";
$page_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name = '".$page_name."' AND post_type = 'page'");

return $page_id;

Thursday, 24 December 2015

How to Disable Auto include Script in WordPress 4.4


How to Disable Auto include Script in WordPress 4.4

In WordPress 4.4 there are some scripts like jQuery, jquery-migrate.min, wp-embed which auto include in page. Here i have displayed how to remover these scripts or How to stop loading these scripts.

Put below function in functions.php

function stop_useless_script(){
if( !is_admin()){
wp_deregister_script('jquery-migrate.min');
wp_deregister_script('jquery');
wp_deregister_script('wp-embed');
}
}
add_action('init', 'stop_useless_script');

Monday, 14 December 2015

WordPress You should update your web.config now - Permalink


WordPress You should update your web.config now - Permalink
To solve this issue

(1)Kindly create the web.config file
(2)Paste the below code in web.config file
(3)Upload it on wordpress root directory.
(4)Change the permalink to post name and check it.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
<rule name="wordpress" patternSyntax="Wildcard">
<match url="*"/>
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
</conditions>
<action type="Rewrite" url="index.php"/>
</rule></rules>
    </rewrite>
  </system.webServer>
</configuration>

Note : How to create web.config file

Open a new text file, paste the code given above in the file.  In the text file go to File->Save As and name it Web.Config and set the Save As Type to All Files

Tuesday, 3 November 2015

Wordpress page not found after form submit


Wordpress page not found after form submit

In my case i have changed the select option name attribute 'Product' to 'Allproduct' and problem has solved.

Kindly change the name of all form field one by one and then check to submit form. Wordpress reserved some keywords that we can not use.

Monday, 2 November 2015

How to get posts from custom post type wordpress


How to get posts from custom post type wordress

Here i have given a simple example. I hope it helps you.

<?php get_header(); ?>

<?php
$args=array(
  'post_type' => 'product',
  'post_status' => 'publish',
  'posts_per_page' => -1
);
?>
<div id="content">

<?php
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <a href="<?php the_permalink() ?>" ><?php the_title(); ?> - <?php echo get_post_meta( get_the_ID(), 'price', true); ?></a>
        <?php
      endwhile;
    }
    wp_reset_query();
    ?>

</div>
<?php get_footer(); ?>

Sunday, 20 September 2015

Disable registration link from wp-login page wordpress


Disable registration link from wp-login page wordpress

In my wordpress blog many fake users come and register in my blog without any purpose so i decided to disable registration link from wp-admin. I have used below code to disable register page.

Just put below code in functions.php of your theme

add_filter('option_users_can_register', disable_register);

function disable_register() {
    $script = basename(parse_url($_SERVER['SCRIPT_NAME'], PHP_URL_PATH));

    if ($script == 'wp-login.php') {
        $value = false;
    }

    return $value;
}

Sunday, 16 August 2015

Remove Register link from wp-login page wordpress


Remove Register link from wp-login page wordpress

In my wordpress blog many fake users come and register in my blog without any purpose so i decided to disable registration link from wp-admin. I have used below code to disable register page.

Just put below code in functions.php of your theme

add_filter('option_users_can_register', disable_register);

function disable_register() {
    $script = basename(parse_url($_SERVER['SCRIPT_NAME'], PHP_URL_PATH));

    if ($script == 'wp-login.php') {
        $value = false;
    }

    return $value;
}

Sunday, 7 December 2014

Create custom meta box in admin wordpress


Create custom meta box in admin wordpress

// Create New meta box
add_action( 'add_meta_boxes', 'add_new_metabox' );

function add_new_metabox()
    {
        add_meta_box('custom_fields', 'Custom Fields', 'my_function');
    }

// function displays your statement
function my_function( $post )
    {
       // your statement
    }

Thursday, 13 November 2014

Wednesday, 12 November 2014

Monday, 3 November 2014

How To Display Related Posts In WordPress


How To Display Related Posts In WordPress

In this post I will show you how to display related posts in WordPress. Open your theme’s single.php file and add following code just above the comments code like below :

// related posts
$related = get_posts( array( 'category__in' => wp_get_post_categories($post->ID), 'numberposts' => 6, 'post__not_in' => array($post->ID) ) );

if( $related ){ ?>
<div class="posts">
<h2>Related Posts</h2>
<ul>
<?php foreach( $related as $post ) {
setup_postdata($post); ?>
    <li>
        <div class="related_post">
        <?php if ( has_post_thumbnail() ) : ?>
            <a title="<?php the_title(); ?>" href="<?php the_permalink(); ?>"><?php the_post_thumbnail(array(150,150) ); ?></a>
        <?php endif; ?>

        <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>
        </div>
    </li>
<?php } ?>
</ul>
</div>
<?php }
wp_reset_postdata();
?>

Tuesday, 2 September 2014

Saturday, 21 June 2014

Action in Wordpress


Action in Wordpress

If you want to add additional code in wordpress core functionality then you can use action.

add_action(wp_head, myfunction);

Filter in Wordpress


Filter in Wordpress

Filter are used to manipulate output like change formatting of content, override array.

add_filter("comment_text", "your_function");