WordPress is very easy to work on. PHP tutorial, how to integrate wordpress into php website. you can very easily integrate the wordpress with php or html site. Here we given code for same.
There may be only a few features of WordPress you want to use when integrating it with your site, or you may want your entire site run with WordPress. This tutorial will guide you through making your WordPress site look like your current design.
how to integrate wordpress into php website
How to start?
First you need to disable the wordpress theme. using following code.
open your header.php file from your wordpress theme and put following code in that file.
<?php
/* Short and sweet */
define('WP_USE_THEMES', false);
require('./wp-blog-header.php');
?>
Create any php file and put following code in that file.
In the event you want to show ten posts sorted alphabetically in ascending order on your web page, you could do the following to grab the posted date, title and excerpt:
Question is, how to protect your images on wordpress. Some time back our server got so much load and bandwidth of server is taken by other websites. preventing images from used by other site is important.
how to protect your images on wordpress
we checked the access to log of my site. we saw the request for my site images through other site. I decided to stop that. Earlier I written good article about this.
I written simple rewrite rule with mod_redirection.
Just open your .htaccess file from your root folder and following code in that.
#Replace ?wordpressapi\.com/ with your blog url
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?wordpressapi\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
#Replace /images/nohotlink.jpg with your "don't hotlink" image url
RewriteRule .*\.(jpe?g|gif|bmp|png)$ /images/nohotlink.jpg [L]
Many times we use the custom post type in wordpress. Wordpres tutorial, In wordpress add tags and categories to custom post type. Some times we need to category and tags for custom post type which associated.
In wordpress add tags and categories to custom post type
you can use the following code in functions.php file.
We solved Allowed memory size of 33554432 bytes exhausted which for wordpress. Given solution for allowed memory. Change given for wordpress/wp-config.php file.
Solved Allowed memory size of 33554432 bytes exhausted
We got always following ERROR PHP Fatal error:
Allowed memory size of 33554432 bytes exhausted (tried to allocate 10485761 bytes)
This issue with old and new wordpress versions both. First you need to increase memory limit for your php package. Use following method for increase the memory for php.
Open php configuration file
# vim /etc/php.ini
Change following sections:
max_execution_time = 300 ; Maximum execution time of each script, in seconds
max_input_time = 300 ; Maximum amount of time each script may spend parsing request data
memory_limit = 128M ; Maximum amount of memory a script may consume (16MB)
After this dont forget to restart apache server.
I know on 2.5.1 i needed to increase the memdory, but i don’t know how in 2.6. in the wp-config.php there no define to increase memory. If you are using old wordpress version less than wordpress 2.6 version or you are using the wordpress MU then use following code. open your wp-settings.php file from root folder and change following line
if ( !defined('WP_MEMORY_LIMIT') )
define('WP_MEMORY_LIMIT', '32M');
to
if ( !defined('WP_MEMORY_LIMIT') )
define('WP_MEMORY_LIMIT', '128M');
If you are using the newer wordpress version greater than 2.7 then use following method. Following URL is also helpful http://codex.wordpress.org/Editing_wp-config.php
#Increasing_memory_allocated_to_PHP Edit wp-config.php and enter the following line
define('WP_MEMORY_LIMIT', '64M');
If you are using the shared hosting then use following method.
Create a file called php.ini in the root of your site (if you are using a hosted addon domain, this must be in the subdirectory of that site)
In php.ini, enter a line that says memory_limit = 64MB 3. In your site’s .htaccess (being a WordPress blog, I’m assuming there is one), enter the following line SetEnv PHPRC // (keep the slashes)
Edit wp-config.php and enter the following line
define('WP_MEMORY_LIMIT', '64M');
Upload the new files to the server Oh, and don’t tell your hosting provider you’ve done this… This will solve your issue.
From wordpress 3.0 version, wordpress started the custom post type functionality. There are API provided by wordpress for adding the pagination for custom post type. Some WP developers asked me about pagination of custom post type. That is very easy to add the pagination. Here in this article I given the code snippet for showing the pagination in custom post type.
solved wordpress custom post type pagination not working
For showing the custom post type we always use the query_post method.
Just use the following code in your template or theme file.
I struggled lot for this issue. Some times I only removed the first image. some times I removed first caption. Using following code you can easily remove the post first image and caption.
How to remove first image from wordpress post with caption if caption is present
I used the following code for first image removing.
/*
* Removing the first image from post
*/
function remove_first_image ($content) {
if (!is_page() && !is_feed() && !is_feed() && !is_home()) {
if (preg_match("/<img[^>]+\>/i",$content)) {
$content = preg_replace("/<img[^>]+\>/i", "", $content, 1);
}
return $content;
}
}
But I faced the some issues with that code. When first image has caption then only image get removed and caption will remain there.
After that I used the following code for caption remove.
/*
* Removing the first caption from post with image
*/
function remove_first_image_caption ($content) {
if (!is_page() && !is_feed() && !is_feed() && !is_home()) {
$content = preg_replace("(\)", "", $content, 1);
} return $content;
}
add_filter('the_content', 'remove_first_image_caption');
But if first image has no caption and second image image has caption then both the images will be get removed from post.
After some struggle I written following code. Following is the solution:
Final Code.
/*
* Removing the first image from post
* functionality added to delete caption is present to first image.
*/
function remove_first_image ($content) {
if (!is_page() && !is_feed() && !is_feed() && !is_home()) {
if (preg_match("/<img[^>]+\>/i",$content)) {
//find first image URL
$first_img = '';
$output = preg_match_all('/< *img[^>]*src *= *["\']?([^"\']*)/', $content, $matches);
$first_img = $matches[1][0];
//find first image caption inner text
$output = preg_match_all("/caption=['"](.*)/", $content, $matches);
//find first image present in first caption text or not
$pos = strpos($matches[0][0], $first_img);
// if image URL found in caption array then delete the caption and image
if ($pos !== false) {
$content = preg_replace("(\)", "", $content, 1);
} else {
$content = preg_replace("/<img[^>]+\>/i", "", $content, 1);
}
}
} return $content;
}
add_filter('the_content', 'remove_first_image');
solved: pagination for Custom post type not working
Some people asked me about pagination of custom post type. That is very easy.
For showing the custom post type we always use the query_post method.
Just use the following code in your template or theme file.
On wordpress home page many sites are showing the post description or we can say the excerpt. For UI purpose some time we need to control the excerpt character limit. I already written about this in following article. But some people need the more advanced excerpt. Following code snippet will be helpful to you show the limit excerpt length by characters in wordpress.
First open your functions.php file and put following code in that file.
[viral-lock message=”Solution code is Hidden! It’s Visible for Users who Liked/Shared This article on Facebook or Twitter or Google+. Like or Tweet this article to reveal the content.”]
we need to show breadcrumbs in wordpress site. For pages and category we can create breadcrumbs in wordpress. Shown, How to create breadcrumbs in wordpress.
How to create breadcrumbs in wordpress
We need to put following code in functions.php file.
Some time people want to show Show selected tags in wordpress from all site. Through selective Tags plugin, you can select the post tags which you want to show. We are very happy to launch the new wordpress plugin called Selective Tags.
How to install Selective Tag Cloud Widget?
Follow the usual routine;
Open WP admin – Plugins – Add New
Enter “Selective Tag Cloud Widget” under search and hit Enter
Plugin will show up as the first on the list, click “Install Now”
Or if needed, upload manually. Follow the steps below to install the plugin.
Upload the Selective Tag Cloud Widget directory to the /wp-content/plugins/directory
Activate the plugin through the ‘Plugins’ menu in wp
Go to “Selective Tag Cloud Widget” option to configure the button
Show selected tags in wordpress using selective Tags plugin
Some time people want to show the only selective tags from all site. Through this widget you can select the post tags which you want to show on your site.
More information about Plugin as follows:
Selective Tag WordPress Plugin, provides sidebar widgets which can be used to display tags in the sidebar.
Selective Tag WordPress Plugin, provides sidebar widgets which can be used to display tags in the sidebar. You can have multiple widgets with different set of tags configured for each one of them.
Each widget allows you to choose
The set of tags displayed which is selected by admin
Admin can select tag to show in sidebar. Auto complete Text box for Tags.
When try to type tags, It will suggest you the used tags from wordpress site.
You can download the plugin from following location.