Viewing 10 replies - 1 through 10 (of 10 total)
  • Shame your other post was closed. It was fully on-topic and the version of WordPress was irrelevant.

    Anyway, there’s no such thing as the before_content_title hook in Customizr, so it won’t work (it will never fire).

    Can you be more precise on exactly where you want it? What about if it’s not a post, but a page? What about if you’re on the list of posts? What about category pages, author pages, etc. What about the front page? When and where do you want it to be displayed in those cases?

    Shame your other post was closed. It was fully on-topic and the version of WordPress was irrelevant.

    The topic was over 9 months old and the version of WordPress is always relevant – not least because it can impact on the version of the theme being used. Also these forums have guidelines. Please read them. As you will see, one of these guidelines – entitled Where to Post – specifically states:

    Unless you are using the same version of WordPress on the same physical server hosted by the same hosts with the same plugins, theme & configurations as the original poster, do not post in someone else’s thread. Start your own topic.

    Thread Starter jrothra

    (@jrothra)

    Actually, per the instructions online (https://www.themesandco.com/customizr/wordpress-actions-filters-and-hooks-a-guide-for-non-developers/), a search shows there is an action hook called “before_content_title.” It’s located in parts/class-content-headings.php on line 375.

    I only want the ad on posts and pages (not category pages, author pages, etc.) Just the two most commonly viewed items. I’d like it right above the post/page title.

    Thread Starter jrothra

    (@jrothra)

    Oops. Apologies, I had my search set to looking for files, rather than looking in the content of files.

    But the hook’s full name is __before_content_title. The two underline characters at the beginning are part of the name and are important.

    Thread Starter jrothra

    (@jrothra)

    I forgot those little things. ?? Oops. I added them in and it works great!

    Thread Starter jrothra

    (@jrothra)

    I just noticed that it places the ad above the title on the home page, too. I don’t want it showing on the home page (www.johnrothra.com — scroll down to see them), but I do want them where they are on the posts themselves. Is there a way to do that?

    You’ll need to put an if clause in there. Right now, based on your other post, I presume you have something like this?

    add_action('__before_content_title' , 'display_my_adsense');
    function display_my_adsense() {
        ?>
            <!-- PASTE YOUR GOOGLE CODE HERE -->
        <?php
    }

    If you don’t want this firing on your home page, then you could make it

    add_action('__before_content_title' , 'display_my_adsense');
    function display_my_adsense() {
        if ( !is_home() ) {
            ?>
                <!-- PASTE YOUR GOOGLE CODE HERE -->
            <?php
        }
    }

    which runs your code only if this is not your home(blog) page.

    However, looking at what you said above–that you only want it showing on posts and pages, but not on category and author pages–it sounds like you need to turn this around and only run the code in a few circumstances, rather than trying to switch it off in many circumstances.

    For just single posts and individual pages, you can use the WordPress conditionals is_single() and is_page(), so your code becomes:

    add_action('__before_content_title' , 'display_my_adsense');
    function display_my_adsense() {
        if ( is_single() || is_page() ) {
            ?>
                <!-- PASTE YOUR GOOGLE CODE HERE -->
            <?php
        }
    }

    More info on WP conditionals here.

    Thread Starter jrothra

    (@jrothra)

    ElectricFeet — those conditionals are exactly what I wanted. Ah, the advantages to knowing how to code.

    Ah, the advantages to knowing how to code.

    Or if you’re not a programmer, gradually getting to know your way around nikeo’s code helps. He has all the tricks in there, it just takes time to be able to find your way around (I’ve managed the highways so far; the small country roads still baffle me).

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Responsive Ad Questions’ is closed to new replies.