wordpress – A Weblog of Priyank Maniar https://priyank.rocks Articles on web development & mobile app development Fri, 23 Jun 2023 07:17:20 +0000 en-US hourly 1 https://wordpress.org/?v=6.6.2 WooCommerce custom code to hide some theme elements https://priyank.rocks/woocommerce-custom-code-to-hide-some-theme-elements/ Fri, 23 Jun 2023 07:16:51 +0000 https://priyank.rocks/?p=9489
1
2
3
4
5
6
7
8
9
10
11
12
13
// Woocommerce, hide the customer reviews ui

jQuery(document).ready(function(){

    jQuery('.woocommerce .woocommerce-product-rating').hide();
    jQuery('.woocommerce .edgtf-social-share-holder').hide();
    jQuery('.woocommerce-tabs .edgtf-tabs-nav').find('li').eq(1).hide();
    jQuery('.woocommerce-tabs .edgtf-tabs-nav').find('li').eq(2).hide();

    // hide related products
    jQuery('.woocommerce .related.products').hide();

});

]]>
WordPress Settings API: Add to header code programmatically https://priyank.rocks/wordpress-settings-api-add-to-header-code-programmatically/ Fri, 01 Oct 2021 15:46:32 +0000 https://priyank.rocks/?p=8444 Develop WordPress custom header code for the backend using the WordPress Settings API.

Programatically develop add code to the header module

1
2
3
4
5
6
7
// source: https://www.codegrepper.com/code-examples/php/wordpress+add+to+header

add_action('wp_head', 'pa_load_fonts');
function pa_load_fonts()
{
    echo get_option("manage_body_font_path");
}
]]>
How to add a custom button to theme my login’s login page? https://priyank.rocks/how-to-add-a-custom-button-to-theme-my-logins-login-page/ Fri, 09 Oct 2020 08:39:15 +0000 https://priyank.rocks/?p=7228
1
2
3
4
5
6
7
8
9
10
11
12
13
    jQuery("document").ready(function(){
       
       

        if(window.location.href.includes("login")) {

                    jQuery('.tml-submit-wrap').append('<button name="submit" type="button" class="tml-button" onclick="window.location=\'https://www.domain.com/LINK\'">Custom Button</button>')

           
        }
       
       
    })
]]>
ThemeMyLogin: How to add a register button to the login page? https://priyank.rocks/thememylogin-how-to-add-a-register-button-to-the-login-page/ Thu, 03 Sep 2020 17:15:20 +0000 https://priyank.rocks/?p=7128 Integration -> Add...]]> The solution was a piece of jQuery code. If you are using Divi, this can be placed in Divi theme options -> Integration -> Add code to the < head > of your blog.

1
2
3
4
5
6
7
8
9
10
11
jQuery("document").ready(function () {


    if (window.location.href.includes("login")) {

        jQuery('.tml-submit-wrap').append('<button name="submit" type="button" class="tml-button" onclick="window.location=\'THE PAGE LINK\'">Become a Tutor</button>')

    }


})
]]>
WordPress function wp_check_filetype https://priyank.rocks/wordpress-wp_check_filetype/ Wed, 05 Aug 2020 07:21:08 +0000 https://priyank.rocks/?p=7092 Retrieves the file type from the file name. Official Docs

Can we pass the URL instead of a filename as the first parameter?

Yes.

]]>
How to Skip the WordPress Logout page confirmation? https://priyank.rocks/how-to-skip-the-wordpress-logout-page-confirmation/ Wed, 29 Jul 2020 16:11:28 +0000 https://priyank.rocks/?p=7050 The following solution worked for me in order to skip the WordPress logout page confirmation.

The WordPress logout page shows when we redirect the user to the logout URL without the nonce.

I was using the plugin theme my login, and I had the option of logout in the Appearance -> Menus section (Screen below).

Using the above logout link, logout process skips the confirmation page and redirects the user directly to the desired page.

Just a theory: May be two kinds of login and perhaps double logging in could trigger this as well such as logged in as tutors as well as admin. Sounds weird. Keep an open mind for this.

]]>
How to remove the custom post type name (CPT) from the URL/Slug? https://priyank.rocks/how-to-remove-the-custom-post-type-name-cpt-from-the-url-slug/ Thu, 16 Jul 2020 16:28:08 +0000 https://priyank.rocks/?p=6949 My usecase was I was having a link domain.com/tutors/tutor-name. The tutors is cpt and the tutor-name is the slug.

Desired output was domain.com/tutor-name.

The following code is an extract from the StackExchange but it contains a few comments that clarify a few things for me.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
 *
 * Source: https://wordpress.stackexchange.com/questions/203951/remove-slug-from-custom-post-type-post-urls
 *
 * Doesn't change the permalink (get_permalink(id)) for the cpt post but the expected link does work with just /slug instead of /tutors(cpt)/slug
 *
 * You can do the following to manipulate the permalink
 *
 * ```
 *
 *   'tutorProfileLink' => str_replace('/tutors/', '/', get_permalink(get_the_ID()))
 *
 * ```
 *
 * Please note the original link of /tutors(cpt)/slug will still be working as is and also /slug will work
 *
 * @param $post_link
 * @param $post
 * @param $leavename
 * @return mixed
 *
 */

function na_remove_slug($post_link, $post, $leavename)
{

    if ('events' != $post->post_type || 'publish' != $post->post_status) {
        return $post_link;
    }

    $post_link = str_replace('/' . $post->post_type . '/', '/', $post_link);

    return $post_link;

}

add_filter('post_type_link', 'na_remove_slug', 10, 3);

function na_parse_request($query)
{

    if (!$query->is_main_query() || 2 != count($query->query) || !isset($query->query['page'])) {
        return;
    }

    if (!empty($query->query['name'])) {
        $query->set('post_type', array('post', 'tutors', 'page'));
    }
}

add_action('pre_get_posts', 'na_parse_request');

I also kept the above settings. Not that it did any magic but just for having the log.

]]>
WordPress dynamic URL for the detail page https://priyank.rocks/wordpress-dynamic-url-for-the-detail-page/ Tue, 16 Jun 2020 17:00:07 +0000 https://priyank.rocks/?p=6785 When we save a record for a CPT the slug is already created, it also takes care of the URL being unique. We just need to take advantage of this setup correctly.

When working with CPT the detail page already exists by default. We only need to use it. You can’t just choose a template for the detail page.

First, you need to create a file called single-tutors.php assuming tutors is your CPT.

This would apply the template file to the file.

For our function of get_page_variables instead of using is_page_template use is_singular(‘tutors’)

]]>
Adding a CPT as a child or nested CPT in the WP admin left sidebar https://priyank.rocks/adding-a-cpt-as-a-child-or-nested-cpt-in-the-wp-admin-left-sidebar/ Thu, 28 May 2020 09:54:45 +0000 https://priyank.rocks/?p=6694 Edit CPT UI – For the item show in the menu, type in following where event_management is a parent post type and the current editing post type becomes a child of it.

edit.php?post_type=event_management

]]>
WooCommerce – Min/Max Quantities https://priyank.rocks/woocommerce-min-max-quantities/ Sun, 01 Mar 2020 16:34:45 +0000 http://priyank.rocks/?p=6243 The plugin BeRocket can be used for this.

]]>