Word press is a best Open Source CMS which enables it to be utilized free of cost. You can utilize it on any sort of individual or business site without paying a solitary penny for it. It is based on PHP/MySQL (which is again Open Source) and authorized under GPL.
Word press is a best Open Source CMS which enables it to be utilized free of cost. You can utilize it on any sort of individual or business site without paying a solitary penny for it. It is based on PHP/MySQL (which is again Open Source) and authorized under GPL.
When talking about WordPress interview questions and answers for experienced, as well as WordPress interviews questions and answers for freshers, one that often comes up is what the requirements to run WordPress are.
Here is what is recommended:
The word press is safe to operate, but still, it is suggested to keep updating with the latest version of WordPress to avoid hacking.
You can use WordPress for e-commerce sites, membership sites, photo galleries and any other type of site you can think of. The website is created using the same HTML code as any other site, so there are no limitations there either.
WordPress was originally used as blogging software though it has since become popular for the website also. It is not necessary to have a blog to use WordPress. Still having a blog is commendable as it will help in search engine optimization.
It is one of the benefits of using WordPress; it has inbuilt SEO search engine. Also, you can have an additional plug-in in WordPress to help with SEO and rank on a popular search engine like Google.
There are two types of hooks 1) Action hooks 2) Filter hooks
Hooks allow a user to create WordPress theme or plugin with shortcode without changing the original files. Action hooks allow you to insert an additional code from an outside resource, whereas, Filter hooks will only allow you to add content or text at the end of the post.
An Action hook in WordPress is a hook that is triggered at a specific time when WordPress is running and lets you take an action. This can include things like creating a widget when WordPress is initializing or sending a Tweet when someone publishes a post.
The custom field is a meta-data that allows you to store arbitrary information in the WordPress post. Through custom field, extra information can be added to the post.
Few positive aspects of WordPress are
By default, wp_ is the prefix for WordPress.
MySQL is widely available database server and is extremely fast. It is an open source, and it is available at no cost also it is supported by many low-cost Linux hosts so its easy for anyone to host their website.
Yes, it is possible to rename the WordPress folder. If WordPress is already installed, you have to log in to the weblog as the administrator and then change the settings
WordPress address (URI) :
Blog address( URI) :
After making the changes, you can rename the folder or directory with the WordPress file in it.
There are about 11 tables in WordPress by default. Note: With succeeding releases of WordPress this number will change. You need to check phpMyAdmin to determine the number of tables in a vanilla version of latest WordPress installation.
WordPress powers more than 28% of the web and this figure is not limited it rises every day.Everything from simple websites, to blogs, to complex portals and enterprise websites, and even applications, are built with WordPress.
Here are some of the features of WordPress.
While developing a WordPress Plugin, the following rules should be followed step by step:
get_site_url(); function is used to get website url in wordpress.
To display error messages in WordPress. Open WordPress wp-cofig.php file and change WP_DEBUG constant value to true
In WordPress, WP_DEBUG is a PHP constant (a permanent global variable) that can be used to trigger the “debug” mode throughout the website.
WordPress contents are stored in MySQL database on Server.
The Loop is PHP code used by WordPress to display posts.
You can enable debug mode in WP by editing wp-config.php file and changing WP_DEBUG constant value to true
In a plugin or in theme functions file, we must create a function that takes text as input, changes it as needed, and returns it. This function must be added as a filter for “the_content”.
It’s important that we put a little effort to address some details:
Only change when we have the full isolate substring “hello”. This will prevent words like “Schellong” from becoming “sgood morningng”. To do that we must use “word boundary” anchors in regular expression, putting the word between a pair of “\b”.
Keep consistency with the letter case. An easy way to do that is to make the replace case sensitive.
<?php
function replace_hello($the_content){
if(current_time('G')<=10){
$the_content=preg_replace('/\bhello\b/','good morning',$the_content);
$the_content=preg_replace('/\bHello\b/','Good Morning',$the_content);
}
return $the_content;
}
add_filter('the_content', 'replace_hello');
<?php
function perform_database_action(){
mysql_query(“INSERT into table_name (col1, col2, col3) VALUES ('$value1','$value2', '$value3');
}
$wpdb is a global variable that contains the WordPress database object. It can be used to perform custom database actions on the WordPress database. It provides the safest means for interacting with the WordPress database.
The code above doesn’t follow WordPress best practices which strongly discourages the use of any mysql_query call. Wordpress provides easier and safer solutions through $wpdb.
The above code can be modified to be as follows:
<?php
function perform_database_action(){
global $wpdb;
$data= array('col1'=>$value1,'col2'=>$value2,'col3'=>$value3);
$format = array('%s','%s','%s');
$wpdb->insert('table_name', $data, $format);
}
add_custom_script();
function add_custom_script(){
wp_enqueue_script(
'jquery-custom-script',
plugin_dir_url( __FILE__ ).'js/jquery-custom-script.js'
);
}
wp_enqueue_script is usually used to inject javascript files in HTML.
The script we are trying to queue will not be added, because “add_custom_script()” is called with no hooks. To make this work properly we must use the wp_enqueue_scripts hook. Some other hooks will also work such as init, wp_print_scripts, and wp_head.
Furthermore, since the script seems to be dependent on jQuery, it’s recommended to declare it as such by adding array(‘jquery’)
as the 3rd parameter.
add_action(‘wp_enqueue_scripts’, ‘add_custom_script’);
function add_custom_script(){
wp_enqueue_script(
'jquery-custom-script',
plugin_dir_url( __FILE__ ).'js/jquery-custom-script.js',
array( 'jquery')
);
}
<?php
add_filter('the_content', 'hello_world');
function hello_world($content){
return $content . "<h1> Hello World </h1>";
}
The file is missing the plugin headers. Every plugin should include at least the plugin name in the header with the following syntax:
<?php
/*
Plugin Name: My hello world plugin
*/
...
</section><!—end of body section- ->
<footer>All rights reserved</footer>
</body>
</html>
All footer files must call the <?php wp_footer() ?>
function, ideally right before the </body>
tag. This will insert references to all scripts and stylesheets that have been added by plugins, themes, and WordPress itself to the footer.
wp_enqueue_script('custom-script', '/js/functions.js');
Assuming that “functions.js” file is in the theme’s “js/” folder, we should use ‘get_template_directory_uri()’. '/js/functions.js'
or the visitors’ browser will look for the file in the root directory of the website.
One obvious way is to download, parse, and cache the blog’s RSS feeds. However, since the blog and the website are on the same server, you can use all the WordPress power, even outside it.
The first thing to do is to include the “wp-load.php” file. After which you will be able to perform any WP_Query and use any WordPress function such as get_posts, wp_get_recent_posts, query_posts, and so on.
<?php
require_once('../blog/wp-load.php');
?>
<h2>Recent Posts</h2>
<ul>
<?php
$recent_posts = wp_get_recent_posts(array(‘numberposts’=>3));
foreach($recent_posts as $recent){
echo '<li><a href="' . get_permalink($recent["ID"]) . '">' . $recent["post_title"] . '</a></li> ';
}
?>
</ul>