Coder Social home page Coder Social logo

Comments (4)

miguelpeixe avatar miguelpeixe commented on August 25, 2024 1

Ads placements have changed a lot since the writing of this issue. You can register new placements by using the Newspack_Ads::register_placement() method.

Example of a custom placement:

/**
 * Register "My Custom Placement" ad placement.
 */
function my_register_placement() {
	if( ! method_exists( '\Newspack_Ads', 'register_placement' ) ) {
		return false;
	}
	$placement_key    = 'my_custom_placement';
	$placement_config = array(
		'name'        => __( 'My Custom Placement', 'my-textdomain' ),
		'description' => __( 'Choose an ad unit to display in this custom placement', 'my-textdomain' ),
		'hook_name'   => 'my_custom_placement',
	);
	\Newspack_Ads::register_placement( $placement_key, $placement_config );
}
add_action( 'init', 'my_register_placement' );

To determine where the ad should be rendered, add the action hook on your theme where you'd like it to be displayed:

<?php do_action( 'my_custom_placement' ); ?>

You can see a full list of available config options:

/**
* Get the available placements.
*
* A placement is an array with the following keys:
* - name: The name of the placement.
* - description: A description of the placement.
* - show_ui: Whether this placement can be edited through the wizard. Default is true.
* - default_enabled: Whether this placement should be enabled by default.
* - default_ad_unit: A default ad unit name to be used for this placement.
* - hook_name: The name of the WordPress action hook to inject an ad unit into.
* - hooks: An array of action hooks to inject an ad unit into.
* - name: The friendly name of the hook.
* - hook_name: The name of the WordPress action hook to inject the ad unit into.
* - supports: An array of supported placement features. Available features are:
* - `stick_to_top`: Whether the placement should be sticky to the top of the page.
*
* @return array Placement objects.
*/

from newspack-ads.

adekbadek avatar adekbadek commented on August 25, 2024

Updated code location

from newspack-ads.

dero avatar dero commented on August 25, 2024

Looks great, thank you for the overview, @miguelpeixe – from my PoV this can be closed.

from newspack-ads.

miguelpeixe avatar miguelpeixe commented on August 25, 2024

Thank you @dero!

from newspack-ads.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.