Skip to main content

Posts

How to Create Your Own WordPress Shortcodes (Without and With Attribute)

WordPress does not allow us to add PHP code to pages, posts or any custom post types. However, we can create custom functions which are executed when a shortcode is encountered within the post text. Simple shortcodes:- Shortcode functions can be added to theme's functions.php file. Here's a simple “Hello World” example: add_shortcode('hello_world', 'my_shortcode_func'); function my_shortcode_func() { return '<p>Hello World!</p>'; } Enter [hello_world] in the required position in a page or post to output the result ( i.e. Hello World!). Shortcodes with Parameters :-  The below shortcode function output image with custom width and height (i.e. you can specify width and height in shortcode)). add_shortcode( 'dynamic_image', 'my_dynamic_image_func' ); function my_dynamic_image_func( $atts = '' ) {     $attributes = shortcode_atts( array(         'width' => 500,         'height' => 300,     ), $atts

How To Add Custom Scripts (Css/Js/HTML) To WordPress Header And Footer (With Plugin)

We frequently need to add a few custom contents to our WordPress sites. From Social (Google, facebook) Analytics code to custom changes, it's very helpful to embed a few contents which needs WordPress. However there is a method for adding extra CSS, you can't actually add any script without updating theme or plugin files. You can add custom code/script to your WordPress sites utilizing a plugin and maybe it's awesome and most secure way on the off chance that you trust the plugin. If you don't need the scripts, you can deactivate or delete the plugin. Using plugin, you can add multiple scripts to header or footer that might be Google Analytics, Google ads, YouTube button, Facebook Like, Pinterest and any other social code. I am sharing some mostly use plugin list which use can use for this. Simple Custom CSS and JS Insert Script In Headers And Footers Insert Custom CSS and JS in Header & Footer Insert Headers and Footers by WPBeginner Custom Header Footer Scripts fo

How to add custom CSS code / JS script to WordPress website (Without Plugin)

 If you want to add script to your website with custom code and don't want to add any plugin or want to add the new functionality to theme or plugin, you just need to add below script in functions.php file. ADD CSS / SCRIPT TO  HEADER add_action( 'wp_head', 'add_custom_script_to_head' ); function add_custom_script_to_head() { ?>     <style>         // Your your css code here     </style>     <script type="text/javascript">         // Your js scripts here     </script> <?php  } ADD CSS / JS SCRIPT TO WP FOOTER add_action( 'wp_footer', 'add_custom_script_to_footer' ); function add_custom_script_to_footer() { ?>      <style>         // Your your css code here     </style>          <script type="text/javascript">         // Your scripts here     </script> <?php }