[Resolved] Question about using a hook for PHP

Home Forums Support [Resolved] Question about using a hook for PHP

Home Forums Support Question about using a hook for PHP

  • This topic has 5 replies, 3 voices, and was last updated 4 years ago by Tom.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1225854
    Andy

    Hi there,

    I’d like to disable mobile zoom. Why? Because I noticed that when I click on a form field or drop-down in mobile view, my phone zooms in.

    I saw in another post, Tom recommended this code (I’m assuming this is the right fix):

    add_filter( 'generate_meta_viewport', 'tu_disable_mobile_zoom' );
    function tu_disable_mobile_zoom() {
        return '<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">';
    }

    I installed Elements, and I watched the video about adding hooks. My only question is, where should I add this PHP code? What part of the theme? What hook? Because I tried the wp_head and footer hooks and it broke my landing page.

    I’m trying to refrain from using a child theme. I know functions.php will work. I thought maybe, a hook would be more efficient? If it isn’t, please let me know.

    Thank you,
    Andy

    #1226037
    David
    Staff
    Customer Support

    Hi there,

    unfortunately you cannot add a filter (hook) inside one of the GP Hook Elements – as all of them are executed on the front end. So it has to go in a child theme, code snippets plugin or your own plugin.

    #1226566
    Andy

    Thanks David, just one more clarification please:

    1. Is a child theme the most light weight option out of those 3 options?

    2. If the answer is yes, can I just download this child theme here?
    https://docs.generatepress.com/article/using-child-theme/

    3. In layman terms, what does this mean? An example would help please. “If the child theme’s style.css file is empty and you’d like to avoid loading it, try this PHP snippet below”

    add_action( 'wp_enqueue_scripts', function() {
        wp_dequeue_style( 'generate-child' );
    }, 50 );

    4. Do I need to make any additional adjustments to this child theme? Or is it good to go “out of the box”? In the past, I’ve installed other child themes and I didn’t do anything else. I’m wondering if I need to do anything fancy with GP’s child theme.

    Thanks so much,
    Andy

    #1226827
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    1. I don’t think there is a more lightweight version. If you already have a child theme, then use it – if not, the other methods are just as good.

    2. Yes, that child theme will work. However, it loads a style.css for the child theme, so if you don’t need the custom CSS, I wouldn’t use a child theme.

    3. This handles what I mentioned above. GP will load the child theme stylesheet by default, if it’s empty, it’s best to remove it.

    4. You may need to re-add your site logo/copyright, as those options are theme-specific.

    #1226909
    Andy

    Thank you!

    #1227513
    Tom
    Lead Developer
    Lead Developer

    No problem 🙂

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.