• Resolved Josue Ardon

    (@josueardon)


    Hello,

    I added a PHP snippet to hide the page titles on my category archive pages like this one here: https://mayangateway.com/category/guatemala-tours/ as you can see in this page, it works, the title is hidden.

    However, I want to run the PHP snippet only on my category archive pages, not in the entire website. I tried to do the following options:
    1. Auto Insert → Frontend Conditional Logic + Enable Logic → Conditions → Show Page URL → is (a few rules with the pages where I need the snippet)
    2. Auto Insert → Frontend Only + Enable Logic → Conditions → Show Page URL → is (a few rules with the pages where I need the snippet)

    After doing each combination, I erased all caches. But none of those options work. At the moment I am using: Auto Insert → Frontend Only without enable logic to make it work.

    Here is the PHP snippet:
    add_action( 'wp', 'lh_remove_archive_title' ); function lh_remove_archive_title() { remove_action( 'generate_archive_title', 'generate_archive_title' ); }

    How can I run the PHP snippet only in the pages where I need it?
    Thank you in advance for your help.

    • This topic was modified 1 year, 5 months ago by Josue Ardon.

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Mircea Sandu

    (@gripgrip)

    Hi @josueardon,

    Page URL rules with the “is” operator are very strict so you need to use the correct URL. At the same time, if you want to use multiple URLs you need to make sure that the rules are set in different Groups so that they work for each of the URLs you want to target – here’s an example: https://a.supportally.com/i/KL0Z5x

    Based on the requirements you mentioned, you might be better off using a taxonomy-based rule instead of URL rules, you can choose the rule “Page Type is Archive” and “Taxonomy Page is Category” https://a.supportally.com/i/MyUED7

    Thread Starter Josue Ardon

    (@josueardon)

    Hi @gripgrip

    Thank you for your quick reply! I tried both options, each one with Frontend Only and Frontend Conditional Logic but none of them work. It only works when I choose Frontend Only and without Enable Logic.

    Plugin Author Mircea Sandu

    (@gripgrip)

    @josueardon can you please also try a minor change to your code and increase the priority of your action? The frontend conditional logic location also uses the “wp” action to make sure everything is loaded and available for checks so it might be preventing it from running correctly.

    So in your code you would have (notice the 15 added to the add_action)

    add_action( 'wp', 'lh_remove_archive_title', 15 ); 
    function lh_remove_archive_title() { remove_action( 'generate_archive_title', 'generate_archive_title' ); }
    Thread Starter Josue Ardon

    (@josueardon)

    Hi @gripgrip, yes this time it worked with this change in code. It worked with Frontend Conditional Logic + the Conditions: type of page and taxonomy page.

    Thank you for your help.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to run a PHP snippet only on the pages where I need it?’ is closed to new replies.