If you are developing a plug-in then this function is the best used for you. Plug-in developers need to specify about refreshing the rewrite rule by visiting the Permalinks options page and pushing the save changes button, nevertheless have made none of the changes. How does it look? A better alternative is creating a code to flush the rewrite rules own self-using the flush_rewrite_rules() function.
How to implement it in practice:
Here is a code that is used to rewrite the rule itself.
// Register Custom Post Type
function portfolio_cpt() {
register_post_type( 'portfolio',
array(
'labels' => array(
'name' => __( 'Portfolios', 'my-locale' ),
'singular_name' => __( 'Portfolio', 'my-locale' )
),
'public' => true,
'has_archive' => true,
)
);
}
add_action( 'init', 'portfolio_cpt', 0 );
function myplugin_activate() {
portfolio_cpt();
flush_rewrite_rules();
}
register_activation_hook( __FILE__, 'myplugin_activate' );
function myplugin_deactivate() {
flush_rewrite_rules();
}
register_deactivation_hook( __FILE__, 'myplugin_deactivate' );
?>
The function is using highest server space among all the functions in WordPress. It is recommended to use it on the activation and deactivation of your plugin or theme.
How to Detect Mobile Visitors to your Website in WordPress?
Do you want to keep watch on who is visiting your site from the mobile source, then here is a function that detects mobile visitors to your website. You can track the mobile visitor's record by the wp_is_mobile() function.
How to implement it in practice: if( wp_is_mobile() ) { // echo the "HAVE YOU TRIED OUR AWESOME MOBILE APP?" banner } else { // don't echo the banner } ?>
How to enqueue CSS in WordPress? When you’re plugin or theme needing variable or inline style, what do you do? You start to write it using wp_enqueue_style()and start enqueuing inline or what!! Well, here I am to provide the best way to do it with slick using wp_add_inline_style() which helps you by letting you include inline CSS style. As simple as adding importing any file into the code!!!
How to implement it in practice: $custom_style_file = get_template_directory_uri(). '/css/custom_style.css'; function custom_styles() { wp_enqueue_style( 'custom-style', $custom_style_file ); $headline_font_weight = get_theme_mod( 'headline-font-weight' ); $custom_style = '.headline { font-weight: ' . $headline_font_weight . '; }'; wp_add_inline_style( 'custom-inline-style', $custom_style ); } add_action( 'wp_enqueue_scripts', 'custom_styles' ); ?>
WordPress function to check that you are in the loop Whenever you develop any plug-in or theme you may check that your code must run in the loop. Here I have an easy way to nail it by using the in_the_loop() function which will increase your efficiency.
How to implement it in practice: if( in_the_loop() ) { // do something loop-related } else { // don't do anything or display some kind of error/warning } ?> Well, Here I am ending up with the wish that it would be helpful to you by any means. I will take out some more such overlooked stuff, so keep following my articles to know more and more and more.
The top technologies course is designed to teach students about the latest and greatest technologies. It will cover topics like web development, cyber security, programming languages, and more. If you want to be successful in the IT field, it's important that you have a good understanding of all the latest technologies. it institute is perfect for anyone who needs to be ready for a career in the IT field. Learn android programming from our expert trainers and gain skills that are in high demand! The training course is perfect for anyone who needs to be ready for a career in the IT field. Learn android programming from our android training institute. We provide the best WordPress Training Course iSurat, Vadodara, Ahmedabad, Rajkot, and Nagpur with live projects and 100% placement assistance.
Author Bio:
Niral Modi works as a Chief Executive Officer at TOPS Technologies, an Education company with an estimated 303 employees; that was founded in 2008. They are part of the Executive team within the C-Suite Department, and their management level is C-Level. Niral is currently based in Chicago, United States.
TOPS Technologies offer the Best Web Development Courses in Ahmedabad, Hardware Training Classes, and Graphic Designing & Web Design Training through Live Project Training. Having tie-ups with 3000+ IT software development companies, We provide a 100% Job Guarantee in Software Development Courses. We are known for our training courses in PHP, Python, Java, Android & iOS, and Asp. Net, C & C++, Angular Courses, IoT, Software Testing, CCNA, Cloud Computing, Ethical Hacking, Hardware Networking, Cyber Security Training, Digital Marketing, MVC Training, and SEO. We also teach Laravel, Nodejs, Unity 3D Game Development, Machine Learning with Python, Data Science, and Linux server training. you can Check out our YouTube channel for more information on any course, such as WordPress, graphic design, and web design, among others.